当前位置: 技术问答>linux和unix
linux shell 小程序总是提示command not found
来源: 互联网 发布时间:2016-11-28
本文导语: 刚学shell,照书写了个程序,怎么改都有command not found,不知道错在哪里。虚拟机下的 suse #!/bin/bash #ifTest.sh #To show the method of If echo -e "Enter te first integer:c" read FIRST echo -n "Enter the second integer:" read SECOND if ...
刚学shell,照书写了个程序,怎么改都有command not found,不知道错在哪里。虚拟机下的 suse
#!/bin/bash
#ifTest.sh
#To show the method of If
echo -e "Enter te first integer:c"
read FIRST
echo -n "Enter the second integer:"
read SECOND
if ["$FIRST" -gt "$SECOND"];
then
echo "$FIRST is greater than $SECOND"
elif ["$FIRST" -lt "$SECOND"];
then
echo "$FIRST is less than $SECOND"
else
echo "$FIRST is equal to $SECOND"
fi
我输入的FIRST是4,SECOND是6
执行后提示:
:line 8:[4:command not found
:line 10:[4:command not found
4 is equal to 6
请高手指点,谢了
上网搜过,说可能是环境变量不对,
但按照网上说的,没找到设置的文件。
#!/bin/bash
#ifTest.sh
#To show the method of If
echo -e "Enter te first integer:c"
read FIRST
echo -n "Enter the second integer:"
read SECOND
if ["$FIRST" -gt "$SECOND"];
then
echo "$FIRST is greater than $SECOND"
elif ["$FIRST" -lt "$SECOND"];
then
echo "$FIRST is less than $SECOND"
else
echo "$FIRST is equal to $SECOND"
fi
我输入的FIRST是4,SECOND是6
执行后提示:
:line 8:[4:command not found
:line 10:[4:command not found
4 is equal to 6
请高手指点,谢了
上网搜过,说可能是环境变量不对,
但按照网上说的,没找到设置的文件。
|
问题在你的shell语句写错了! 缺少空格!
if ["$FIRST" -gt "$SECOND"];
elif ["$FIRST" -lt "$SECOND"];
这2句改成
if [ "$FIRST" -gt "$SECOND" ];
elif [ "$FIRST" -lt "$SECOND" ];
看到去别了吗!
if [空格"$FIRST" -gt "$SECOND"空格];
elif [空格"$FIRST" -lt "$SECOND"空格];
if ["$FIRST" -gt "$SECOND"];
elif ["$FIRST" -lt "$SECOND"];
这2句改成
if [ "$FIRST" -gt "$SECOND" ];
elif [ "$FIRST" -lt "$SECOND" ];
看到去别了吗!
if [空格"$FIRST" -gt "$SECOND"空格];
elif [空格"$FIRST" -lt "$SECOND"空格];