1、for-for嵌套
#!/bin/bash
for (( a = 1; a <= 5; a++ ))
do
echo "外层循环,此时a=$a:"
for (( b =1; b <=3; b++ ))
do
echo " 内层循环,此时b=$b;"
done
done
2、while-for嵌套
#!/bin/bash
var1=7
while [ $var1 -ge 0 ]
do
echo "外层循环,此时var1=$var1"
for (( var2 = 1; var2 < 4; var2++ ))
do
var3=$[ $var1 * $var2 ]
echo " 内层循环,var3=$var3"
done
var1=$[ $var1 - 1 ]
done
3、until-while嵌套
#!/bin/bash
var1=4
until [ $var1 -eq 0 ]
do
echo "外层循环,此时var1=$var1"
var2=1
while [ $var2 -lt 5 ]
do
var3=$(echo "scale=3; $var1 / $var2" | bc)
echo " 内层循环,var3=$var3"
var2=$[ $var2 + 1 ]
done
var1=$[ $var1 - 1 ]
done