shell指令碼測試
阿新 • • 發佈:2019-01-08
1.判斷輸入是否是數字,並且輸出簡單圖形
#!/bin/bash read -p "input a num: " num #判斷輸入是否是數字,直到輸入正確數字為止 flag=true while $flag do if [ -n "$num" ];then test=$(echo "$num"|sed 's/[0-9]//g') if [ -z "$test" ];then flag=false fi fi [ "$flag" == "false" ] || read -p "input correct num: " num done for (( i=1;i<=$num;i++ )) do for j in $(seq 1 $i) do echo -n "*" done echo done echo "############" for (( i=$num;i>=1;i-- )) do for j in $(seq 1 $i) do echo -n "*" done echo done
2.測試結果: