用shell编写一个三角形图案
第一种方法
#!/bin/bash
read -p "请输入层数: " n
for (( i=1; i<=$n;i++ ))
do
for (( j=n; j>=i;j-- ))
do
echo -n " "
done
for (( j=1;j<=i;j++ ))
do
echo -n " *"
done
echo
done
另外一种方案:三角形简单
#!/bin/bash
for i in {1..9}
do
for a in {1..9}
do
if [ $a -ge $i ]
then
echo -n " "
fi
done
for b in {1..9}
do
if [ $b -le $i ]
then
echo -n "*"
fi
done
for h in {1..9}
do
if [ $h -lt $i ]
then
echo -n "*"
fi
done
echo
done
用代码改变命运,加油,努力,陌生人!