bash字符串与多个正确值进行比较
问题描述:
我有以下bashscript:
i have the following piece of bashscript:
function get_cms {
echo "input cms name"
read cms
cms=${cms,,}
if [ "$cms" != "wordpress" && "$cms" != "meganto" && "$cms" != "typo3" ]; then
get_cms
fi
}
但是无论我输入什么(正确和错误的值),它都不会再调用该函数,因为我只想允许这3个输入之一.
我已经尝试过||与[ var != value ] or [ var != value1 ] or [ var != value1 ]
但没有任何效果.
有人可以指出我正确的方向吗?
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.
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
您可能还想参考有条件的构造.