Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我希望检查正确的用户输入(伪代码)
userInput="" #check until user enters 'y' OR 'Y' OR 'n' OR 'N' while [[ "$userInput" != "[yYnN]" ]] ; do read userInput done
我的想法是使用[]通配符进行匹配,但完成此任务的正确方法是什么?
[]
这是一种方法:
while true; do case $userInput in y|Y|n|N) break ;; *) # read more input ;; esac done
如果您不关心可移植性,您可以使用
while [[ ! $userInput =~ [yYnN] ]]; do