红联Linux门户
Linux帮助

linux 小程序运行出错

发布时间:2012-03-06 21:04:38来源:红联作者:xcf0423
源程序是这样的
#!/bin/sh
echo "enter password"
read trythis
while [ "$trythis" !=" secret" ];do
echo "sorry,try again"
read trythis
done
exit 0
书上提示的运行结果是
enter password
password
sorry,try again
secret
$
可是我运行的结果是
[root@localhost ~]# /bin/sh while
enter password
password
while: line 4: [: password: unary operator expected
[root@localhost ~]#
求解释
文章评论

共有 3 条评论

  1. tianfeng1988 于 2013-02-26 10:10:38发表:

    初学Linux,{:2_92:},各位大侠多多关照

  2. GJ1203 于 2013-02-23 20:59:55发表:

    shell编程对于空格的位置要求很严格....注意检查...

  3. 于 2012-03-07 19:20:57发表:

    while [ "$trythis" !=" secret" ];do
    改成
    while [ "$trythis" != "secret" ];do
    注意空格位置。