您的位置:首页 > 其它

72.打印正方形脚本

2021-01-21 22:34 976 查看
思路:for内嵌实现打印正方形
#!/bin/bash
#The script is used to add square.
#Date 2021-01-21
while :
do
read -p "please input a number: " n
n1=`echo $n |sed 's/[0-9]//g'`
if [ -z $n ];then#判断输入是否为空
echo "The input can not be empty."
continue#重新循环
elif [ -n "$n1" ];then#判断输入是否为数字
echo "The input must be numeric."
continue#重新循环
else
break#退出循环
fi
done
for i in `seq 1 $n`
do
for j in `seq 1 $n`
do
echo -n "● "#不换行输出
done
echo #换行
done

输出结果:
please input a number: 2
● ●
● ●
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: