Following my previous question, I have write the following MWE to create a simple file selector by date
filesArr=( $(ls -1rt ??????????_?) )
nfiles=${#filesArr[@]}
iLastFile=$[nfiles-1]
choiceArr=( )
for i in `seq 0 $iLastFile`; do
filesSN[i]=${filesArr[i]:11:1}
year=${filesArr[i]:0:2}
month=${filesArr[i]:2:2}
day=${filesArr[i]:4:2}
hour=${filesArr[i]:6:2}
min=${filesArr[i]:8:2}
wday=`date -d $month/$day/$year '+%a'`
filesDate[i]="'$wday $day/$month/$year $hour:$min'"
choiceArr=( ${choiceArr[@]} "'${filesSN[i]}'" "${filesDate[i]}" )
done
#choiceArr=( '4' 'Fri 23/01/15 10:09' '1' 'Mon 02/02/15 09:15' '3' 'Wed 25/03/15 11:38' '2' 'Sat 18/04/15 23:45' )
echo ${choiceArr[@]}
dialog --title "Backup target file" \
--radiolist "Select the file to replace" 15 60 4 \
"${choiceArr[0]}" "${choiceArr[1]}" ON \
"${choiceArr[2]}" "${choiceArr[3]}" OFF \
"${choiceArr[4]}" "${choiceArr[5]}" OFF \
"${choiceArr[6]}" "${choiceArr[7]}" OFF 2>/tmp/menu.sh.$$
The problem is that this mixes the choices in the radio list
(*) '4' 'Fri
( ) 23/01/15 10:09'
( ) '1' 'Mon
( ) 02/02/15 09:15'
However, if I create the array using the same for loop, print it on screen and then assign it explicitely to the same variable (i.e. uncommenting the commented line), it works fine.
Does anyone has any suggestions?
choiceArr=( ${choiceArr[@]} ...
you haven't quoted${choiceArr[@]}
. Or use the simplerchoiceArr+=( "'${filesSN[i]}'" "${filesDate[i]}" )
. – muru Apr 28 '15 at 11:16(Should I copy your comment as an accepted answer, or it is better if you do it?)
– Theo Apr 28 '15 at 11:21