I'm trying to reverse a 1-D array which contains a list of files. I followed https://stackoverflow.com/questions/13360091/how-to-reverse-array-in-bash-onliner-for-loop to be the code. But this is not quite working for me.
for (( i=${#FILES_dcn[@]}-1,j=0 ;i>=0;i--,j++ ));
do
dcnarray[j] = ${FILES_dcn[i]}
done
The values are not getting copied when I echo the arrays onto a file. Why is that??
asked Mar 21, 2014 at 12:20
2 Answers 2
If you trim the spaces around the =
it will work fine:
dcnarray[j]=${FILES_dcn[i]}
Michael Mrozek
95.6k40 gold badges245 silver badges236 bronze badges
There must be no space around =
in variable assignments.
BTW, with zsh
:
dcnarray=("${(@Oa)FILES_dcn}")
answered Mar 21, 2014 at 12:38
You must log in to answer this question.
lang-bash