#!/bin/bash # 读取用户输入的正整数n read -p "" n # 循环打印等腰三角形 for ((i=1; i<=n; i++)); do # 打印前导空格 for ((j=n-i; j>0; j--)); do echo -n " " done # 打印星号和空格组合 for ((k=1; k<=i; k++)); do echo -n "* " done # 换行 echo done
#!/bin/bash # 读取用户输入的正整数n read -p "" n # 循环打印等腰三角形 for ((i=1; i<=n; i++)); do # 打印前导空格 for ((j=n-i; j>0; j--)); do echo -n " " done # 打印星号和空格组合 for ((k=1; k<=i; k++)); do echo -n "* " done # 换行 echo done