while 循环读取值并检查 2 个可能的答案 - bash/centOS

while loop that reads value and checks for 2 possible answer - bash/centOS

我在这个 while 循环中遇到问题,我试图检查从用户输入中读取的 'choice' 值是否不等于 'yes' 或 'false'。现在验证捕获任何不是 'yes' 或 'no'.

的东西

问题是,当用户输入'yes'或'no'...

时,验证也会进入while循环

有没有人知道发生了什么以及我如何才能让它发挥作用?

while read choice && ([[ "$choice" != "yes" ]] || [[ "$choice" != "no" ]]); do
        echo -n "'$choice' is invalid choice, enter 'yes' or 'no': ";
done

提前致谢!

你打错了。应该是 ([[ "$choice" != "yes" ]] && [[ "$choice" != "no" ]])

while read choice && ([[ "$choice" != "yes" ]] && [[ "$choice" != "no" ]]); do
    echo -n "'$choice' is invalid choice, enter 'yes' or 'no': ";
done