[ 来源: | 作者: | 时间:2007-07-17 | 收藏 | 推荐 ] 【大 中 小】
casewordin[pattern[|pattern]...)list;;]...esac
case/esac的标准用法大致如下:
case$argin
pattern|sample)#arginpatternorsample
;;
pattern1)#arginpattern1
;;
*)#default
;;
esac
arg是您所引入的参数,如果arg内容符合pattern项目的话,那麽便会执行pattern以下的程式码,而该段程式码则以两个分号";;"做结尾。
可以注意到"case"及"esac"是对称的,如果记不起来的话,把"case"颠倒过来即可。
--------------------------------------------------------------------------------
例一:paranoia
#!/bin/sh
case$1in
start|begin)
echo"startsomething"
;;
stop|end)
echo"stopsomething"
;;
*)
echo"Ignorant"
;;
esac
执行
[foxman@foxmanbash]#chmod755paranoia
[foxman@foxmanbash]#./paranoia
Ignorant
[foxman@foxmanbash]#./paranoiastart
startsomething
[foxman@foxmanbash]#./paranoiabegin
startsomething
[foxman@foxmanbash]#./paranoiastop
stopsomething
[foxman@foxmanbash]#./paranoiaend
stopsomething
--------------------------------------------------------------------------------
(编辑:IT资讯之家 www.it55.com)