在Bash中循环遍历数组

时间:2019-03-01 12:54:25

标签: bash for-loop

当我使用rclone时,我试图遍历Bash中的数组。我已经设置了一个路径数组,并且正在遍历它们,但是我也想在控制台窗口中回显路径名。当我运行代码时,由于路径中包含空格,所以echo命令显示路径的每个部分,而不是整个路径。这是我的代码;

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

我看到的是

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

我想看到的是完整的路径字符串。不确定我在这里做错了什么,我想这是folder[*]中的引用导致了我这个问题。

0 个答案:

没有答案
相关问题