shell脚本实例

1.打印形状

等腰三角形

 1 #!/bin/bash
 2 # 打印等腰三角形
 3 read -p "Please input the length: " n
 4 for i in `seq 1 $n`
 5 do
 6    for ((j=$n;j>i;j--))
 7    do
 8     echo -n " " 
 9    done
10 
11    for m in `seq 1 $i`
12    do
13     echo -n "* "
14    done
15    echo 
16 done

 

倒直角三角形

 1 #!/bin/bash
 2 #倒直角三角形
 3 read -p "Please input the length: " len
 4 for i in `seq 1 $len`
 5 do
 6    for j in `seq $i $len`
 7    do
 8       echo -n "* "
 9    done
10    echo
11 done

 

直角三角形

 1 #!/bin/bash
 2 #直角三角形
 3 read -p "Please input the length: " len
 4 for i in `seq 1 $len`
 5 do
 6     for ((j=1;j<=$i;j++))
 7     do
 8         echo -n "* "
 9     done
10     echo
11 done

 

菱形

 1 #!/bin/bash
 2 #菱形
 3 
 4 read -p "Please input the length: " n
 5 
 6 for i in `seq 1 $n`
 7 do
 8    for ((j=$n;j>i;j--))
 9    do
10        echo -n " "
11    done
12    for m in `seq 1 $i`
13    do
14        echo -n "* "
15    done
16    echo
17 done
18 
19 for i in `seq 1 $n`
20 do
21    for ((j=1;j<=$i;j++))
22    do
23       echo -n " "
24    done
25    for ((k=$i;k<=$len-1;k++))
26    do
27       echo -n "* "
28    done
29    echo
30 done
posted @ 2020-01-01 08:25  随便写写~  阅读(136)  评论(0编辑  收藏  举报