2017-06-02 80 views
1

我在我的bash腳本中收到一個錯誤,我沒有看到任何錯誤。這是給我錯誤的代碼。Bash腳本錯誤:第167行:意外標記附近的語法錯誤'然後'

if [ "$password" = "na" ]; then 
    log "Password not set" 
    usage 
    exit 1 
fi 

任何人都可以看到有什麼不對嗎?它對我來說看起來很好,但對於bash來說,我也很新。

編輯:這裏是前面的代碼行,也許這將有所幫助。

if [ "$SITE" = "unknown" ]; then 
    log "Site not set" 
    usage 
    exit 1 
fi 

if [ "$VERSION" = "na" ]; then 
    log "Version not set" 
    usage 
    exit 1 
fi 

if [ "$password" = "na" ]; then 
    log "Password not set" 
    usage 
    exit 1 
fi 
+0

也許錯誤是在一些前行? – airos

+2

大概回車。 – 123

+1

我猜想這是一個嵌套的if/then,我們需要看到前面的代碼行。 – SaintHax

回答

0

您的示例對我來說無誤。我猜你的文件可能包含'隱藏'字符(很可能是'\ r' - 回車 - 但可能是其他內容)。用於本地Vi/Vim系列編輯來避免這種情況;否則,請檢查文本編輯器中的設置,並將「行結束符」設置爲Unix/OSX。試試這個:

tr -d '\r' /path/your_file.sh > /path/your_file.mod.sh 

bash -n /path/your_file.sh  ## should show error 
bash -n /path/your_file.mod.sh ## no errors 

:)
戴爾

相關問題