【发布时间】:2017-10-13 09:47:36
【问题描述】:
以下 while 循环旨在不断询问用户输入,直到输入指定的“中断”字符。但是,出于某种原因,无论输入什么文本,都会触发此 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
在脚本中,我将用户输入变量声明为User_Input="";
据我所知,if 语句是正确的,并且脚本在运行时没有抛出任何错误。
【问题讨论】:
-
如果您阅读the Bash manual page,您将看到
==运算符是用于双括号表达式(即在[[ ... ]]中)的特定于Bash 的扩展。对于单括号,您应该阅读thetestmanual page。
标签: bash