Weather : overcast
一、需求:
寫一個shell腳本,檢查指定的shell腳本是否有語法錯誤,如有錯誤,首先顯示錯誤信息,而後提示用戶輸入q或者Q退出腳本,輸入其餘內容則直接用vim打開該shell腳本。shell
[root@Dasoncheng sbin]# cat h.sh #!/bin/bash sh -n $1 &>/tmp/err if [ $? -eq 0 ]; then echo "The script is ok" else cat /tmp/err read -p "Please input q/Q to exit , or others to edit it by vim: " n if [ "$n" == "q" ] || [ "$n" == "Q" ]; then exit else vim $1 exit fi fi