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
● ● 
● ●
相關文章
相關標籤/搜索