区分大小写的参数Bash

时间:2015-10-05 07:39:16

标签: bash arguments

我在区分大小写的参数(bash)中遇到了麻烦,所以基本上当我输入

<div class="box">
  <label>
    <input type="checkbox" name="check"><span> Check me</span>
  </label>
</div>

./testfile -play

./testfile -p

脚本必须运行&#34; play&#34; (函数名称)echo&#34; test test 123&#34;在testfile.sh中

同时,如果我输入

,它也会显示 &#34;无效!&#34; 等错误消息
./testfile -palalalal

我非常感谢能帮助我的人。谢谢。

1 个答案:

答案 0 :(得分:2)

使用case运算符:

case "$1" in
    -p*) play ;;
    -P*) echo "Invalid" ;;
    *) echo "Still invalid" ;;
esac