SHELL脚本之case

  • 一般形式
case variable in
    pattern1 | pattern2)
        command;;
    pattern3)
        command;;
    *)
        default command;;
esac
  • 例子
#!/bin/bash
case $USER in
    root | user)
        echo "Welcome.$USER"
        echo "Please enjoy your visit";;
    testing)
        echo "Special testing acount";;
    *)
    echo "Sorry,you are not allowed here";;
esac