1

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??

3

If you trim the spaces around the = it will work fine:

dcnarray[j]=${FILES_dcn[i]}
| improve this answer | |
3

There must be no space around = in variable assignments.


BTW, with zsh:

dcnarray=("${(@Oa)FILES_dcn}")
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.