原文:shell報錯:-bash: [: ==: 期待一元表達式 解決方法 ([: ==: unary operator expected)

shell報錯: bash: : : 期待一元表達式 解決方法 : : unary operator expected blogdaren 搶沙發 人次 問題背景: if flag then mode dev else mode test fi 如上代碼, 執行shell報錯:line : : : unary operator expected 翻譯過來就是: bash: : : 期待一元表達式 ...

2019-05-13 12:24 0 2076 推薦指數:

查看詳情

shell報錯:-bash: [: ==: 期待一元表達式 解決方法

問題背景: if [ "$frut" == '2' ]; then mode='--run' else mode='' fi 如上代碼, 執行shell報錯:-bash: [: ==: 期待一元表達式 解決方法: 看見 $frut 變量了嗎,必須加上引號 ...

Fri May 25 01:06:00 CST 2018 1 10167
Shell腳本報錯unary operator expected

在匹配字符串時用了類似這樣的語句 if[ $timeofday = "yes"]; then echo "Good morning" exit 0 報錯的原因是:如果變量timeofday的值為空,那么就if語句就變成了if [ ="yes" ],這不是一個合法 ...

Fri Jul 19 20:07:00 CST 2013 0 37351
shell腳本執行報錯[: 0: unary operator expected

在執行shell腳本,if判斷語句報錯 #!/bin/bash if [ 0 == $testNum ] then echo "Check Result:0" fi    testNum使用時沒有定義,無賦值是空(原本是有定義的,只是筆誤寫錯類似tsetNum了),執行 ...

Tue Jul 10 04:34:00 CST 2018 0 7246
shell腳本報錯:"[: =: unary operator expected"

shell腳本報錯:"[: =: unary operator expected" 在匹配字符串相等時,我用了類似這樣的語句: if [ $STATUS == "OK" ]; then echo "OK" fi 在運行時出現了 [: =: unary ...

Thu Jan 24 00:56:00 CST 2019 0 561
shell腳本執行出現“期待整數表達式

在執行shell時一直出現“integer expression expected”,找了很久也沒發現那個地方出錯。翻了筆記發現-le並不錯啊,甚至還懷疑零是不是整數還特意上網搜了下 -_- 。 最后發現是因為在變量前沒有加上$符,才會瘋狂報錯報錯的時候顯示在第6行看了好久,並沒發現問題 ...

Mon Dec 16 06:04:00 CST 2019 0 1107
[: -ge: unary operator expected 錯誤

運行報錯 : line 5: [: -ge: unary operator expected 錯誤原因: 由於變量rate初始化賦值為空,那么就成了 [ -ge "10"] 了,顯然 [ 和 "10" 不相比較並且缺少了 [ 符號,所以報了這樣的錯誤。 解決 ...

Sun Oct 11 02:25:00 CST 2015 0 2092
 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM