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 @ 2022-02-14 15:38  箫笛  阅读(37)  评论(0)    收藏  举报