【shell 】syntax error in conditional expression
編寫shell 指令碼時遇見 syntax error in conditional expression 錯誤,
#!/bin/bash
# cleanup /var/log/message
LOG_DIR=/var/log
ROOT_DID=0
LINES=50
E_XCD=66
E_NOTROOT=67
if [[ "$UID" -ne "$ROOT_UID"]]
then
echo "Must be root to run this script."
exit $E_NOTROOT
fi
if [ -n "$1"]
then
lines=$1
else
lines=$LINES
fi
.......
root@client.example.com # sh test.sh
test.sh: line 12: syntax error in conditional expression
test.sh: line 13: syntax error near `then'
test.sh: line 13: `then'
仔細檢視是由於 if 條件中的中括號[ ]與變數之間必須有空格
root@client.example.com # vi test.sh
#!/bin/bash
# cleanup /var/log/message
LOG_DIR=/var/log
ROOT_DID=0
LINES=50
E_XCD=66
E_NOTROOT=67
if [[ "$UID" -ne "$ROOT_UID" ]]
then
echo "Must be root to run this script."
exit $E_NOTROOT
fi
if [ -n "$1"]
then
lines=$1
else
lines=$LINES
fi
.....
"test.sh" 60L, 793C written
修改以後,再次執行成功
root@client.example.com # sh test.sh 20
Logs cleaned up
#!/bin/bash
# cleanup /var/log/message
LOG_DIR=/var/log
ROOT_DID=0
LINES=50
E_XCD=66
E_NOTROOT=67
if [[ "$UID" -ne "$ROOT_UID"]]
then
echo "Must be root to run this script."
exit $E_NOTROOT
fi
if [ -n "$1"]
then
lines=$1
else
lines=$LINES
fi
.......
root@client.example.com # sh test.sh
test.sh: line 12: syntax error in conditional expression
test.sh: line 13: syntax error near `then'
test.sh: line 13: `then'
仔細檢視是由於 if 條件中的中括號[ ]與變數之間必須有空格
root@client.example.com # vi test.sh
#!/bin/bash
# cleanup /var/log/message
LOG_DIR=/var/log
ROOT_DID=0
LINES=50
E_XCD=66
E_NOTROOT=67
if [[ "$UID" -ne "$ROOT_UID" ]]
then
echo "Must be root to run this script."
exit $E_NOTROOT
fi
if [ -n "$1"]
then
lines=$1
else
lines=$LINES
fi
.....
"test.sh" 60L, 793C written
修改以後,再次執行成功
root@client.example.com # sh test.sh 20
Logs cleaned up
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/22664653/viewspace-689293/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- Syntax error, unrecognized expression: li[value=]ErrorZedExpress
- shell 指令碼報錯^M: syntax error near unexpected token指令碼Error
- syntax error near unexpected token `Error
- exp tables sh: Syntax error: `(' is not expectedError
- Solaris syntax error: unexpected end of fileError
- Oracle安裝報錯syntax errorOracleError
- line 10:syntax error: unexpected end of fileError
- 配置NDK syntax error: unexpected end of file 解決Error
- 萬能方法解決——You have an error in your SQL syntaxErrorSQL
- syntax error near unexpected token `問題的解決Error
- error C2061: syntax error : identifier '__RPC__out_xcount_part'ErrorIDERPC
- [Shell] awk學習(3)-regular expression 正規表示式Express
- 解決報錯error the @annotation pointcut expression is only supported at Java 5ErrorExpressJava
- pecl PHP Parse error: syntax error, unexpected 'new' (T_NEW) 以及 XML缺失解決辦法PHPErrorXML
- 解決laravel出現Syntax error or access violation: 1055 ‘***‘ isn‘t in GROUP BYLaravelError
- 360 Atals:Cause: java.sql.SQLException: Proxy Warning - near “status“: syntax errorJavaSQLExceptionError
- eclipse 引入外部js檔案報Syntax error on token 錯解決方案EclipseJSError
- 執行遷移檔案報錯: Syntax error or access violation: 1166 ...Error
- CentOS7使用exp/imp時報錯:bash: syntax error near unexpected token `(CentOSError
- Mail To SyntaxAI
- Expression BlendExpress
- TypeScript 之 Conditional TypesTypeScript
- Syntax Error: ValidationError: Invalid options object. Stylus Loader has been initialized using anErrorObjectZed
- Laravel 8使用 佇列任務出現 「 syntax error, unexpected ')' 」錯誤解決Laravel佇列Error
- Linux 5中出現的-bash: syntax error near unexpected token `('錯誤LinuxError
- Solaris awk: syntax error near line 1 awk: bailing out near line 1ErrorAI
- Springboot中配置動態sql查詢出現的錯誤syntax error, expect ‘)‘Spring BootSQLError
- ACM Arithmetic ExpressionACMExpress
- Expression Date FunctionsExpressFunction
- aix login shell permission error trouble shooting.AIError
- VS Could not evaluate expressionExpress
- Spring註解之@ConditionalSpring
- DB2:SQL1024N和ksh: 0403-057 Syntax error: `(' is not expected.報錯DB2SQLError
- Hibernate 與 MySql 資料庫關鍵字衝突You have an error in your SQL syntax; check the manualMySql資料庫Error
- std::map initializer list syntax ?
- Spring條件註解@ConditionalSpring
- SpringBoot(15)—@Conditional註解Spring Boot
- .net好好地利用Conditional屬性