标签:for http ++ bin xxxxx mic one 变量 while
#!/bin/bash
#九九乘法表
i=1
while [ $i -le 9 ]
do
for (( j=1;j<=9;j++ ))
do
[ $j -le $i ]&& echo -n "$i$j=$((ij)) "
done
echo " "
let i++
done
1 1= 1
21=2 22=4
31=3 32=6 33=9
41=4 42=8 43=12 44=16
51=5 52=10 53=15 54=20 55=25
61=6 62=12 63=18 64=24 65=30 66=36
71=7 72=14 73=21 74=28 75=35 76=42 77=49
81=8 82=16 83=24 84=32 85=40 86=48 87=56 88=64
91=9 92=18 93=27 94=36 95=45 96=54 97=63 98=72 9*9=81
#!/bin/bash
#直角三角形
i=1
while [ $i -lt 10 ] //变量i小于10
do
j=1
while [ $j -le $i ] //变量j 小于等于变量i
do
echo -n x //输出X
j=$(($j+1))
done
echo
i=$(($i+1))
done
exit 0
~
x
xx
xxx
xxxx
xxxxx
xxxxxx
xxxxxxx
xxxxxxxx
xxxxxxxxx
#!/bin/bash
#等腰三角形
i=1
while [ $i -le 10 ] ; do //变量i小于等于10
j=1
while [ $j -le $((10-$i)) ] ; do
echo -n ‘
j=$(($j+1))
done
j=1
while [ $j -le $((2*$i-1)) ] ; do
echo -n x
j=$(($j+1))
done
echo
i=$(($i+1))
done
exit 0
~
x
xxx
xxxxx
xxxxxxx
xxxxxxxxx
xxxxxxxxxxx
xxxxxxxxxxxxx
xxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxx
xxxxxxxxxxxxxxxxxxx
#!/bin/bash
read -p"请输入菱形的长度: " fff
for((i=1;i<=$fff;i++)) //控制行数
do
for((j=$fff;j>i;j--)) //控制空格
do
echo -n " "
done
let "g=2*i-1"
for m in `seq 1 $g` //控制*数量,输出2个
do
echo -n "*"
done
echo ""
done
for((i=2;i<=$fff;i++))
do
for ((j=1;j<i;j++))
do
echo -n " "
done
let "k=2*(fff-i)+1"
#!/bin/bash
read -p "请输入正方形的长度: " ggg
for ((i=1;$i<=$ggg;i++))
do
for ((j=1;j<=$((2*$ggg));j++))
do
echo -e "+\c"
done
echo
done
[root@localhost ~]# ./ggg.sh
请输入正方形的长度: 5
++++++++++
++++++++++
++++++++++
++++++++++
++++++++++
[root@localhost ~]# ./ggg.sh
请输入正方形的长度: 7
++++++++++++++
++++++++++++++
++++++++++++++
++++++++++++++
++++++++++++++
++++++++++++++
++++++++++++++
Shell脚本(乘法表,直角三角形,等腰三角形,任意交互式菱形,任意交互式正方形)
标签:for http ++ bin xxxxx mic one 变量 while
原文地址:https://blog.51cto.com/14449524/2440339