我正在尝试运行一个非常简单的脚本,该脚本从用户读取输入,并在用户输入与预期不匹配时连续循环问题。
它正在通过bash执行:
echo "Specify a directory [Y/N]?"
read ans
while [ [ "$ans" != "Y" ] || [ "$ans" != "y" ] || [ "$ans" != "N" ] || [ "$ans" != "n" ] ]
do
echo "$ans is not valid, please answer [Y/N]"
read ans
done
代码继续......
知道为什么这不起作用?这似乎是一个非常直接的循环。
答案 0 :(得分:1)
这应该有效:
echo "Specify a directory [Y/N]?"
read ans
while [ "$ans" != "Y" ] && [ "$ans" != "y" ] && [ "$ans" != "N" ] && [ "$ans" != "n" ]
do
echo "$ans is not valid, please answer [Y/N]"
read ans
done
有一些错误:
[ ]