判断一个指定的脚本是否是语法错误;如果有错误,则提醒用户键入Q或者q无视错误并退出,其它任何键可以通过vim打开这个指定的脚本;


#!/bin/bash

script_file="./test.sh"

sh -n $script_file>/dev/null 2 >/dev/null

n=`echo $?`

if [ $n -ne 0 ];then

    read -p "this script is a bad file , "q" or "Q"---exit ,other key to edit the file : " key

    if [$key == 'q' -o $key == 'Q' ] 

        then

            exit

       else

            vi $script_file

    fi

fi