shell编程 - 条件语句

1. if-then 语句

if command
then
  commands
fi

2. if-then-else 语句

if command
then
  commands
else
  commands
fi

3. if-then-elif-then-else 语句

if command1
then
  commands
elif command2
then 
  commands
else
  commands
fi

4. case语句

case $variable in 
pattern1 | pattern2) 
  commands1;;
pattern3) 
  commands2;;
*)
  commands;;
esac

检查一个变量可能是多个值时,可以采用case 语句,替代if-then-elif-then-else语句

posted @   箫笛  阅读(34)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 微软正式发布.NET 10 Preview 1:开启下一代开发框架新篇章
· 没有源码,如何修改代码逻辑?
· PowerShell开发游戏 · 打蜜蜂
· 在鹅厂做java开发是什么体验
· WPF到Web的无缝过渡:英雄联盟客户端的OpenSilver迁移实战
点击右上角即可分享
微信分享提示