linux case命令

case命令用于处理一连串的匹配需求

语法格式:

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

举例:

#!/bin/bash
case $USER in
root | tom)
  echo "welcome $USER";;
*)
  echo "hi $USER";;
esac

 

posted @ 2022-04-22 19:46  zed99  阅读(47)  评论(0编辑  收藏  举报