#!/bin/bash
# ——————————————–
# Filename: svim.sh
# Revision: 1.0v
# Date: 2018-04-10
# Author: LiDongfei
# Email: 652117746@qq.com
# Website: http://www.cnblogs.com/L-dongf
# Description: This is the create shell script
# ———————————————
# Copyright: 2018 Dongfei
# License: GPL
#一个函数,功能是退出时自动检查语法并提示
Edit() {
while [ “$Choice” != ‘N’ ]; do
ErrorLineNum=`bash -n $1 2>&1 |head -1 |tr ‘ ‘ ‘:’ |cut -d: -f4`
vim +${ErrorLineNum:-13} $1
ErrorLineNum=`bash -n $1 2>&1 |head -1 |tr ‘ ‘ ‘:’ |cut -d: -f4`
if bash -n $1 &>/dev/null; then
break
else
read -p “Syntax Error(line number: ${ErrorLineNum:-‘Unknown’}) Please connect? (y,N): ” Choice
fi
done
}
#判断用户的参数是否为一个,否则退出
[ “$#” -ne 1 ] && echo “Usage: `basename $0` script.sh” && exit 1
#判断用户参数是否以.sh结尾,如果不是则以vim打开,如果是.sh结尾,则执行以下脚本
if [[ ! “$1” =~ .+\.sh$ ]]; then
vim $1
exit 3
fi
#读入一个配置文件用于赋值
. /etc/svim.conf
#判断用户输入的文件是不是一个已存在的文件,如果不存在则创建一个并自动加入脚本描述信息
if [ ! -e “$1″ ]; then
cat >>$1 <<EOF
#!/bin/bash
# —————————————–
# Filename: ${1%.*}.sh
# Revision: 1.0v
# Date: `date +%F`
# Author: ${Author:-none}
# Email: ${Email:-none}
# Website: ${Website:-none}
# Description: This is the ${1%.*} script
# —————————————–
# Copyright: @2018 ${Copyright:-none}
# License: GPL
EOF
chmod +x $1
Edit $1
else
Edit $1
fi
附配置文件示例:
vim /etc/svim.conf
Author=”XXXX”
Email=”XXXX”
Website=”XXXX”
Copyright=”XXXX”
如果有错误的地方还请各位大佬相告之,感激不尽!!
本文来自投稿,不代表Linux运维部落立场,如若转载,请注明出处:http://www.178linux.com/97490