0

I'm trying to loop through an array in Bash when using rclone. I have set up an array of paths, and I'm looping through them, but I also want to echo the path name in the console window. When I run my code, because the paths have spaces in them, the echo command shows each part of the path, instead of the whole path. Here is my code;

folder[0]="a path here"
folder[1]="another path here"
folder[2]="another path here"
folder[3]="another path here"

for item in ${folder[*]}; do
  echo "syncing $item ..."
  rclone copy ~/"Documents/$item" Box:"$item" -u -vv --syslog
done

What I see is

syncing 'a' ... 
syncing 'path' ... 
syncing 'here' ... 
syncing 'another' ...
syncing 'path' ...
syncing 'here' ...

What I want to see is the full path string. Not sure what I'm doing wrong here, I guess it's the referencing in the folder[*] causing me the problem.

Spanakop
  • 9
  • 2
  • 2
    do this `"${folder[@]}"` make sure you wrap the array in double qutoes – 0.sh Mar 01 '19 at 12:57
  • 1
    More info, when variable are put inside single quotes, they are not expanded. – dibery Mar 01 '19 at 13:11
  • I tried using the @ symbol before, but it did not work, I guess the magic part was the inclusion of the quote marks around the variable. Thanks – Spanakop Mar 01 '19 at 13:25
  • 2
    Quoting `${folder[@]}` is the sole reason `@` exists along with `*`. More generally, parameter expansions should *always* be quoted until you discover a reason not too. – chepner Mar 01 '19 at 13:31

0 Answers0