bash 意外标记“else”附近的语法错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23307842/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
syntax error near unexpected token `else'
提问by Matt
I am new to Linux and Shell scripting so please help me with some patience Could you please let me know if the bash is in my path or not. how to find it in future
我是 Linux 和 Shell 脚本的新手,所以请耐心帮助我如果 bash 是否在我的路径中,请告诉我。以后怎么找
Below is the error
下面是错误
./test.sh: line 5: syntax error near unexpected token `else'
./test.sh: line 5: `else'
below is my PATH /u01/app/oracle/product/10.2.0/db_1/bin:/usr/sbin:/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr/X11R6/bin:/home/oracle/bin
下面是我的路径 /u01/app/oracle/product/10.2.0/db_1/bin:/usr/sbin:/usr/kerberos/bin:/usr/local/bin:/usr/bin:/bin:/usr /X11R6/bin:/home/oracle/bin
which bash /bin/bash
哪个 bash /bin/bash
Below is the simple if statment in shell scripting. I use vi editor
下面是 shell 脚本中的简单 if 语句。我使用 vi 编辑器
#!/bin/bash -x
age=10;
if(age -lt 13)
echo "$age"
else
echo "xx"
Any information is highly appreciable.
任何信息都是高度可观的。
Matt
马特
回答by gangadhars
- Don't end a statement with
;
. This is not c/c++/java program. - Conditions in script are enclosed with
[]
not()
- Please read how to use
if
statement/syntax. Do google and then try.
- 不要以
;
. 这不是 c/c++/java 程序。 - 脚本中的条件用
[]
not括起来()
- 请阅读如何使用
if
语句/语法。做谷歌然后尝试。
Syntax of if
:
的语法if
:
if [ conditional expression ]
then
#statements
...
fi
So your program is:
所以你的程序是:
#!/bin/bash
age=10
if [ $age -lt 13 ]
then
echo "something"
else
echo "some other thing"
fi