Shell 命令 2 -- case in

多条件判断,if else

#!/bin/bash

if [ $USER = "test1" ]
then
    echo "Welcome $USER"
elif [ $USER = "test2" ]
then
   echo "Welcome $USER"
elif [ $USER = "testing" ]
then
   echo "Hello $USER"
elif [ $USER = "testno" ]
then
   echo  "Welcome $USER.Do not forget to poweroff compute"
else
   echo "Nothing"
fi

转成case in

#!/bin/bash

case $USER in
test1|test2)
      echo "Welcome,$USER";;
testing)
      echo "Hello,$USER";;
testno)
    echo "Welcome $USER.Do not forget to poweroff compute";;
*)
    echo "Nothing!";;
esac  

case in语法

每行以双分号结尾

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

猜你喜欢

转载自blog.csdn.net/c123m/article/details/89498211