While Loop" [string:command not found"

时间:2016-03-04 08:28:14

标签: bash

我有一个while循环来确定用户是否输入了一个新行,并且一旦用户输入任何内容而退出,则会退出,但是包含以下代码段的新行:

...
while [$abc -e ""]
do
read -p " enter something besides new line " abc
done
...

假设用户按下“输入”键。 4次,然后是“someNonNewLineString'输出将是

enter something besides new line

enter something besides new line 

enter something besides new line 

enter something besides new line 

line 1 [someNonNewLineString: command not found

从控制的角度来看,它按照预期的方式工作,因为一旦用户输入除“输入”之外的任何内容,该循环就会退出。但为什么最后一条声明返回说找不到命令?

另外,这是接近这个的正确方法(检测用户是否输入新行,如果是,则重新提示其他内容)?

1 个答案:

答案 0 :(得分:1)

使用[]周围的空格,使用=进行比较。

while [ "$abc" = "" ]