首页 > 其他 > 详细

case逻辑判断基数还是偶数

时间:2016-02-18 12:06:57      阅读:191      评论:0      收藏:0      [点我收藏+]

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

case逻辑判断基数还是偶数

原文:http://461205160.blog.51cto.com/274918/1742921

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!