所以我知道如何循环 1 个变量:
folder="(first|second|third)"
for i in "${folder[@]}"; do
rclone move /mounts/$folder/cache
done
但是当他们2岁的时候该怎么办呢?
folder="(first|second|third)"
mount="(something1|something2|something3)"
for i in "${folder[@]}"; do
rclone move /mounts/$folder/cache $mount
done
因此脚本应该循环每个文件夹并添加正确的安装。
最后,执行应该是这样的:
rclone move /mounts/first/cache something1
rclone move /mounts/second/cache something2
rclone move /mounts/third/cache something3
答案1
您需要迭代数组指数数字而不是值。这是使用${!folder[@]}
语法完成的。
这样您就可以通过循环内的相同索引访问两个数组
例如(echo
在这个例子中放在前面)
folder=(first second third)
mount=(something1 something2 something3)
for i in "${!folder[@]}"; do
echo rclone move /mounts/${folder[$i]}/cache ${mount[$i]}
done
会输出
rclone move /mounts/first/cache something1
rclone move /mounts/second/cache something2
rclone move /mounts/third/cache something3