72.打印正方形脚本

思路: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
● ● 
● ● 
上一篇:Java:标示符 基本数据类型


下一篇:[BZOJ1798] [Ahoi2009]Seq 维护序列seq