<code> #!/bin/bash #name:create script #description: #auth:feiyu #version:0.0.1 #datatime : 2015-07-23 #useage:mksh FILENAME while getopts ":d:" args;do case $args in d): DESC=$OPTARG ;; ?): # ?表示任意字符 echo "Usage: mksh [ -d description ] FILENAME " esac done shift $[$OPTIND-1] if ! grep "[^[:space:]]" $1 &> /dev/null ;then cat << EOF > $1 #/bin/bash #name:`basename $1` #description:$DESC #auth:feiyu #datatime:`date +%F` #usage:mksh FILENAME EOF fi vim + $1 until bash -n $1 &> /tmp/test/check ; do cat /tmp/test/check read -p "syntax error,q|Q for quiting,others for opening:" opt case $opt in q|Q): echo "quit" exit 1 ;; *): vim $1 ;; esac done chmod +x $1 </code>
此脚本能创建 bash shell 脚本并检查其语法,使用时请给其 +x 权限,然后将其放在 PATH 下,以后就可以直接使用了,非常方便!