区分大小写的参数 Bash

Case-Sensitive Argument Bash

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

./testfile -play

./testfile -p

./testfile -palalalal

脚本必须 运行 一个 "play"(函数名称)在 testfile.sh

中回显 "test test 123"

同时,如果我输入

,它也会显示类似"invalid!"的错误信息
./testfile -PLAYYY

我真的很感激任何能帮助我的人。谢谢。

使用case运算符:

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