gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-04 19:37:49 24 4
gpt4 key购买 nike

我遇到了这个while循环的问题,我试图检查从用户输入中读取的“选择”值是否不等于"is"或“假”。现在验证会捕获任何不是"is"或“否”的东西。

问题 就是说,当用户输入"is"或“否”时,验证也会进入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

关于bash - while 循环读取值并检查 2 个可能的答案 - bash/centOS,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33666467/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com