Draw graphics with shell
Commonly used commands
echo -n: output without line break
echo -e: support character conversion controlled by backslashes
Escape:
\a: sound a warning
\b: delete the previous character
\c: do not add a newline symbol at the end
\f: wrap but the cursor Stay at the original position
\n: wrap the line and move the cursor to the beginning of the line
\r: move the cursor to the beginning of the line, but not wrap the line
\t: insert tab
\v: same as
\ f \: insert\character
\nnn: mix in ASCII characters represented by nnn (octal)
Usage of
seq seq 10 #start default is 1, interval default is 1, output result (1-10)
seq 2 10 #start value is 2, default interval is 1, output result (2-10)
seq 1 3 10 #The initial value is 1, the default interval is 3, and the output result: 1 4 7 10
Square shape
[root@server6 ~]# vim zf.sh
#!/bin/bash
# 正方形图形
for (( j=1;j<=5;j++ ))
do
for (( i=1;i<=5;i++ ))
do
echo -n "* "
done
echo
done
[root@server6 ~]#chmod +x zf.sh
[root@server6 ~]# ./zf.sh
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
Rectangular shape
[root@server6 ~]#vim zf.sh
#!/bin/bash
# 正方形图形
for (( j=1;j<=7;j++ ))
do
for (( i=1;i<=5;i++ ))
do
echo -n "* "
done
echo
done
[root@server6 ~]#chmod +x zf.sh
[root@server6 ~]#./zf.sh
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
* * * * *
triangle
Right triangle (the first type)
#!/bin/bash
# 三角形图形
for ((j=1;j<=7;j++))
do
for ((i=1;i<=$j;i++))
do
echo -n "*"
done
echo
done
[root@server6 ~]#chmod +x zf.sh
[root@server6 ~]#./zf.sh
*
**
***
****
*****
******
Right triangle (the second type)
[root@server6 ~]#vim zj.sh
#!//bin/bash
# 直角三角形
for ((i=1;i<=9;i++))
do
for ((j=1;j<$i;j++))
do
echo -n " "
done
for ((k=10-$j;k>0;k--))
do
echo -n "*"
done
echo
done
[root@server6 ~]#chmod +x zj.sh
[root@server6 ~]#./zj.sh
*********
********
*******
******
*****
****
***
**
*
Isosceles triangle
[root@server6 ~]#vim dysj.sh
#!/bin/bash
# 等腰三角形
for ((i=1;i<10;i++))
do
for ((j=10;j>=i;j--))
do
echo -n " "
done
for ((k=1;k<=i;k++))
do
echo -n "* "
done
echo
done
[root@server6 ~]#chmod +x dysj.sh
[root@server6 ~]#./dysj.sh
*
* *
* * *
* * * *
* * * * *
* * * * * *
* * * * * * *
* * * * * * * *
* * * * * * * * *
diamond
[root@server6 ~]#vim lx.sh
#!/bin/bash
# 菱形
read -p "输入菱形长度:" len
for i in `seq 1 $len`
do
for ((j=$len-1;j>=$i;j--))
do
echo -n " "
done
for ((m=1;m<=$i;m++))
do
echo -n "* "
done
echo
done
for i in `seq 1 $len`
do
for ((j=1;j<=$i;j++))
do
echo -n " "
done
for ((n=$len-1;n>=$i;n--))
do
echo -n "* "
done
echo
done
[root@server6 ~]#chmod +x lx.sh
[root@server6 ~]#./lx.sh
输入菱形长度:5
*
* *
* * *
* * * *
* * * * *
* * * *
* * *
* *
*
9*9 multiplication formula table
The first multiplication formula table
[root@server6 ~]#vim xfkj.sh
#!/bin/bash
# 乘法口诀表
for ((i=1;i<=9;i++))
do
for ((j=1;j<=i;j++))
do
echo -ne "$i*$i=$((i*i)) \t"
done
echo
done
[root@server6 ~]#chmod +x xfkj.sh
[root@server6 ~]#./xfkj.sh
1*1=1
2*2=4 2*2=4
3*3=9 3*3=9 3*3=9
4*4=16 4*4=16 4*4=16 4*4=16
5*5=25 5*5=25 5*5=25 5*5=25 5*5=25
6*6=36 6*6=36 6*6=36 6*6=36 6*6=36 6*6=36
7*7=49 7*7=49 7*7=49 7*7=49 7*7=49 7*7=49 7*7=49
8*8=64 8*8=64 8*8=64 8*8=64 8*8=64 8*8=64 8*8=64 8*8=64
9*9=81 9*9=81 9*9=81 9*9=81 9*9=81 9*9=81 9*9=81 9*9=81 9*9=8
Multiplication formula table (the second type)
[root@server6 ~]#vim xfkj.sh
#!/bin/bash
# 乘法口诀表
for ((i=1;i<=9;i++))
do
for ((j=1;j<=9;j++))
do
echo -ne "$i*$i=$((i*i)) \t"
done
echo
done
[root@server6 ~]#chmod +x xfkj.sh
[root@server6 ~]#./xfkj.sh
1*1=1 1*1=1 1*1=1 1*1=1 1*1=1 1*1=1 1*1=1 1*1=1 1*1=1
2*2=4 2*2=4 2*2=4 2*2=4 2*2=4 2*2=4 2*2=4 2*2=4 2*2=4
3*3=9 3*3=9 3*3=9 3*3=9 3*3=9 3*3=9 3*3=9 3*3=9 3*3=9
4*4=16 4*4=16 4*4=16 4*4=16 4*4=16 4*4=16 4*4=16 4*4=16 4*4=16
5*5=25 5*5=25 5*5=25 5*5=25 5*5=25 5*5=25 5*5=25 5*5=25 5*5=25
6*6=36 6*6=36 6*6=36 6*6=36 6*6=36 6*6=36 6*6=36 6*6=36 6*6=36
7*7=49 7*7=49 7*7=49 7*7=49 7*7=49 7*7=49 7*7=49 7*7=49 7*7=49
8*8=64 8*8=64 8*8=64 8*8=64 8*8=64 8*8=64 8*8=64 8*8=64 8*8=64
9*9=81 9*9=81 9*9=81 9*9=81 9*9=81 9*9=81 9*9=81 9*9=81 9*9=81