Shell编程进阶 1.7 case选择
逻辑判断的格式
vim case.sh
#!/bin/bash read -p "please input a number:" n m=$[$n%2] case $m in 1) echo " It is a jishu'" ;; 0) echo " It is a oushu." ;; *) echo " Not is a jishu and oushu." esac
输入一串字符 赋值$n
$m=$n除以2
判断$m
等于1
输出这是个奇数
等于0
输出这是个偶数
等于其他
输出这不是奇数和偶数
#!/bin/bash read -p "please input a number:" n w=`echo $n |sed 's/[0-9]//g'` if [ -n "$w" ] then echo "Not is a number,please input a number." else echo $n fi m=$[$n%2] case $m in 1) echo " It is a jishu'" ;; 0) echo " It is a oushu." ;; *) echo " Not is a jishu and oushu." esac