我正在尝试写类似下面的东西
for i in {a..z} && j in {1..26}
do
echo "/dev/sd"$i"1 /disk$j ext4 noatime 1 1" >> test
done
当然这不是正确的语法。有人可以用正确的语法帮助我吗?
最佳答案
为了通用,您可以使用“长度”,如下所示。
#!/bin/bash
# Define the arrays
array1=("a" "b" "c" "d")
array2=("w" "x" "y" "z")
# get the length of the arrays
length=${#array1[@]}
# do the loop
for ((i=0;i<=$length;i++)); do
echo -e "${array1[$i]} : ${array2[$i]}"
done
你也可以像下面这样给数组赋值
array1=`awk -F" " '$1 == "CLIENT" { print $2 }' clientserver.lst`
关于bash 脚本循环多个变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18773160/