直角三角形
vim zhijiao.sh
输入以下内容:
#!/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
例:
测试:
等腰三角形:
vim dengyao.sh
请输入以下内容:
#!/bin/bash
read -p "请输入你想要的等腰三角形:" n
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
例:
测试: