0
以下while循环旨在不断询问用户输入,直到输入指定的“break”字符。但是,由于某些原因,无论输入什么文本,都会触发IF语句。IF语句触发时不包含真正的语句
while true; do
#Prompt user for Input
printf "Please insert value. Insert the letter 'D' when you are done\n";
#Read User Input
read User_Input;
echo "DEBUG: Input is: $User_Input";
#Check User Input for Break Command
if [ "$User_Input"=="D" ]; then
break
fi
done
而且脚本中的我有用户输入变量至于我可以告诉if语句是正确的,该脚本不抛出任何错误,当运行宣布为User_Input="";
。
如果您阅读[Bash手册页](http://man7.org/linux/man-pages/man1/bash.1.html),您会看到'=='运算符是Bash - 用于双括号表达式的特定扩展(即'[[...]]')。对于单支架,您应该阅读[test'手册页](http://man7.org/linux/man-pages/man1/test.1.html)。 –