方法1
var1="a b c"
var2="1 2 3"
set -- $var2
for i in $var1
do
echo $i $1
shift
done
方法2
folder=(first second third)
mount=(something1 something2 something3)
for i in "${!folder[@]}"; do
echo move /mounts/${folder[$i]}/cache ${mount[$i]}
done
方法3
is=(a b c d)
js=(1 2 3 4)
for ((i = 0; i < 4; i++))
do
echo ${is[i]} ${js[i]}
done
参考
- https://unix.stackexchange.com/questions/390283/how-to-iterate-two-variables-in-a-sh-script
- https://unix.stackexchange.com/questions/561655/loop-through-variable-in-bash-using-2-variables
- https://www.unix.com/shell-programming-and-scripting/75414-sh-two-variables-loop.html