如何将字符串与 Bash 中的多个正确值进行比较?
问题描述:
我有以下 Bash 脚本:
I have the following piece of Bash script:
function get_cms {
echo "input cms name"
read cms
cms=${cms,,}
if [ "$cms" != "wordpress" && "$cms" != "meganto" && "$cms" != "typo3" ]; then
get_cms
fi
}
但是无论我输入什么(正确和不正确的值),它都不会再次调用该函数,因为我只想允许这 3 个输入中的 1 个.
But no matter what I input (correct and incorrect values), it never calls the function again, because I only want to allow 1 of those 3 inputs.
我用 ||
、[ var != value ] 或 [ var != value1 ] 或 [ var != value1 ]
尝试过,但没有任何效果.
I have tried it with ||
, with [ var != value ] or [ var != value1 ] or [ var != value1 ]
, but nothing works.
有人能指出我正确的方向吗?
Can someone point me in the right direction?
答
而不是说:
if [ "$cms" != "wordpress" && "$cms" != "meganto" && "$cms" != "typo3" ]; then
说:
if [[ "$cms" != "wordpress" && "$cms" != "meganto" && "$cms" != "typo3" ]]; then
您可能还想参考条件构造.