一.打印三角
1.图一
#!/bin/bash
# 1
# 22
# 333
# 4444
# 55555
# 666666
# 7777777
# 88888888
# 999999999
for i in $(seq 9); do
for ((j = 1; j <= i; j++)); do
echo -n "$i"
done
echo ""
done
2.第二个图
#!/bin/bash
# |_
# ||_
# |||_
# ||||_
# |||||_
for i in $(seq 5); do
for ((j = 1; j <= i; j++)); do
echo -n "|"
done
echo "_"
done
3.第三个图
#!/bin/bash
# *
# * *
# * * *
# * * * *
# * * * * *
# * * * * *
# * * * *
# * * *
# * *
# *
# 方法一
for ((i = 1; i <= 5; i++)); do
for ((j = 1; j <= i; j++)); do
echo -n " *"
done
echo ""
done
for ((i=5; i>=1; i--)); do
for((j=1;j<=i;j++));do
echo -n " *"
done
echo ""
done
# 方法二
for i in $(seq 10); do
if [ $i -gt 6 ]; then
for m in $(seq $((11 - i))); do
echo -n "* "
done
elif [ $i -eq 6 ]; then
for j in $(seq $((i - 1))); do
echo -n "* "
done
else
for j in $(seq $i); do
echo -n "* "
done
fi
echo
done
标签:bin,do,12,seq,打印,三角形,bash
From: https://www.cnblogs.com/ckh2023/p/17757478.html