#!/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”
如果有錯誤的地方還請各位大佬相告之,感激不盡?。?/p>
本文來自投稿,不代表Linux運維部落立場,如若轉載,請注明出處:http://www.www58058.com/97490