case逻辑判断基数还是偶数
1
2
3
4
5
6
7
8
9
10
11
12
13
|
#!/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
本文转自 boy461205160 51CTO博客,原文链接:http://blog.51cto.com/461205160/1742921