红联Linux门户
Linux帮助

请教各位大侠,关于Shell文本编译时的问题

发布时间:2010-06-26 20:52:37来源:红联作者:psl7758
这个是shell文本
#!/bin/sh


echo "Is it morning? Please answer yes or no:"

read timeofday

if [ "$timeofday" = "yes" ]; then

echo "Good morning"

elif [ "$timeofday" = "no" ]; then

echo "Good afternoon"

else

echo "Sorry, $timeofday not recognized. Enter yes or no"

exit 1

fi

exit 0



本来有错的,我看着改了错误,编译时出现了问题,大家看下
win@ubuntu:~$ chmod +x elif2
win@ubuntu:~$ ./elif2
: not found
Is it morning? Please answer yes or no:
yes
: bad variable name
./elif2: 7: Syntax error: "elif" unexpected (expecting "then")


这是为啥阿,几乎所有这类程序都是这种错误
文章评论

共有 4 条评论

  1. mg271603433 于 2011-01-05 18:33:32发表:

    顶一个。

  2. meycine 于 2010-11-25 15:35:48发表:

    这种喝楼主用的if句型有什么区别啊??

  3. JK409 于 2010-06-27 12:44:08发表:

    你可以换一种
    if [ ];then
    else ...
    if [];then
    ..........
    else ......
    fi
    fi

  4. bobo504 于 2010-06-27 08:53:49发表:

    和你问的另一个问题一样,改成#!/bin/bash