##99乘法表while双重嵌套
i=1
while ((i<=9))
do
j=1
while ((j<=i))
do
echo -n "$j*$i=$((j*i)) "
((j++))
done
echo ""
((i++))
done
##99乘法表for双重嵌套
for ((i=1; i<=9; i++))
do
for ((j=1; j<=i; j++))
do
echo -n "$j*$i=$((j*i)) "
done
echo ""
done
##三角形while if嵌套
read -p "输入三角形层数>>>" cnum
i=1
j=1
while ((i<=cnum))
do
if ((j<=i))
then
echo -n "*"
((j++))
else
((i++))
echo ""
j=1
fi
done
##三角形for另一种形式
read -p "输入三角形层数>>>" cnum
for i in `seq $cnum`
do
for j in `seq $i`
do
echo -n "*"
done
echo ""
done
###获取字符串空格
read -p "输入一个字符串>>>" strs
i=0
j=0
for((i; i<=${#strs}; i++))
do
if [ "${strs:$i:1}" == ' ' ]
then
((j++))
fi
done
echo "空格个数:"$j