首先准備1個測試shell文件test.sh,內容如下,第2行hello沒有用 雙隱號括起來(有語法錯誤)
echo "hello1" echo "hello
然后在shell腳本所在目錄,執行命令:
bash -n test.sh
這個命令是用來檢查shell語法格式是否正確
效果如下:
wangju@wangju-HP-348-G4:~/Desktop$ bash -n test.sh test.sh: line 2: unexpected EOF while looking for matching `"'
test.sh: line 3: syntax error: unexpected end of file
可以看到執行完檢查shell語法格式是否正確后,給出我們錯誤提示信息: unexpected EOF while looking for matching `"'
最后修改test.sh,把第2行hello用雙隱號括起來(使其沒有語法錯誤)
echo "hello1" echo "hello"
再次執行bash-n test.sh檢查語法,效果如下: