1个简单的case脚本:


# vi aa.sh

#!/bin/bash


case $1 in

      "foo")

    echo 'bar'

       ;;

      "bar")

     echo 'foo'

       ;;

          *)

     echo 'error'

       ;;

esac


:wq


# sh aa.sh foo  (输入foo,输出bar)

# sh aa.sh bar  (输入bar,输出foo)

# sh aa.sh aa   (输入其它,输出error)


$1表示添加到shell中的第1个参数(即执行脚本后面跟的第1个英文)