标签:root str i++ shel bash -o *** size div
1.首先我们先打印直角三角形
1 #!/bin/bash
2
3 read -p "输入金字塔层数: " line
4
5 for((i=1;i<=line;i++))
6 do
7 for((j=1;j<=i;j++))
8 do
9 echo -n "*"
10 done
11 echo
12 done
[root@logan day3]# bash jzt.sh
输入金字塔层数: 5
*
**
***
****
*****
2.金字塔
1 #!/bin/bash
2
3 read -p "输入金字塔层数: " line
4 for((i=1;i<=line;i++))
5 do
6 for((k=1;k<=line-i;k++))
7 do
8 echo -n " "
9 done
10 for((j=1;j<=2*i-1;j++))
11 do
12 echo -n "*"
13 done
14 echo
15 done
输入金字塔层数: 5
*
***
*****
*******
*********
3.空心金字塔
1 #!/bin/bash
2
3 read -p "输入金字塔层数: " line
4 for((i=1;i<=line;i++))
5 do
6 for((k=1;k<=line-i;k++))
7 do
8 echo -n " "
9 done
10 for((j=1;j<=2*i-1;j++))
11 do
12 if [ $i -eq 1 -o $i -eq $line ]
13 then
14 echo -n "*"
15 else
16 if [ $j -eq 1 -o $j -eq $((2*$i-1)) ]
17 then
18 echo -n "*"
19 else
20 echo -n " "
21 fi
22 fi
23 done
24 echo
25 done
输入金字塔层数: 5
*
* *
* *
* *
*********
标签:root str i++ shel bash -o *** size div
原文地址:https://www.cnblogs.com/MR-ws/p/11110717.html