case逻辑判断基数还是偶数
#!/bin/bash read -p "please input a number: " a b=$[ $a%2 ] case $b in 1) echo "the number is odd " ;; 0) echo "the number is even" ;; *) echo "it is not a odd or even" ;; esac
注:*) echo "it is not a odd or even",只是语句完善,因为输入无论数字还是字符串不是0就是1
[root@Linux9 ~]# sh case.sh
please input a number: 2333
the number is odd
[root@Linux9 ~]# sh case.sh
please input a number: 6666
the number is even
本文出自 “boyhack” 博客,请务必保留此出处http://461205160.blog.51cto.com/274918/1742921
原文:http://461205160.blog.51cto.com/274918/1742921