概述
- 没有对比,就没有伤害,先来看一下使用else if有多麻烦
[root@foundation8 test]# cat if_complex.sh
#!/bin/bash
#looking for a possible value
if [ $USER = "student" ];then
echo "Welcome $USER"
echo "Please enjoy your visiting!"
elif [ $USER = "Bob" ];then
echo "Welcome $USER"
echo "Please enjoy your visiting!"
elif [ $USER = "Alice" ];then
echo "Welcome $USER"
echo "Please enjoy your visiting!"
elif [ $USER = "Coco" ];then
echo "Welcome $USER"
echo "Please enjoy your visiting!"
else
echo "Sorry,you're not allowed here."
fi
[root@foundation8 test]# sh if_complex.sh
Sorry,you're not allowed here.
- case闪亮登场
[root@foundation8 test]# cat case_better.sh
#!/bin/bash
#using the case command
case $USER in
student|Bob|Alice|Coco)
echo "Welcome $USER"
echo "Please enjoy your visiting!"
;;
*)
echo "Sorry,you're not allowed here."
esac
[root@foundation8 test]# sh case_better.sh
Sorry,you're not allowed here.
最后
以上就是威武巨人为你收集整理的Shell脚本之case语句的全部内容,希望文章能够帮你解决Shell脚本之case语句所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复