欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

shell编程 case语句

发布时间:2025/4/5 编程问答 29 豆豆
生活随笔 收集整理的这篇文章主要介绍了 shell编程 case语句 小编觉得挺不错的,现在分享给大家,帮大家做个参考.
case语句格式
# vi test.sh
:
echo "input : "
read num
echo "the input data is $num"

case $num in
1) echo"January";;    双分号结束
2) echo "Feburary";;
5) echo"may"         每个case可以有多条命令      
   echo "sdfd"
   echo"sdf";;       但最后一条命令一定是双分号结束

*) echo "not correct input";;   *)是其他值、default的意思     

esac   
# sh ./test.sh
input :
2
the input data is 2
Feburary

# sh ./test.sh
input :
ter
the input data is ter
not correctinput   

 
    case 语句如果某个选项没有任何语句,也要加;;否则会出下边错误
test: line 166: syntax error near 《新程序员》:云原生和全面数字化实践50位技术专家共同创作,文字、视频、音频交互阅读

总结

以上是生活随笔为你收集整理的shell编程 case语句的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。