SHELL创建脚本工具
#!/bin/bash#
#
#
# 判断文件是否存在
Sh=$(echo $1 | grep -o'.sh$')
#if ! [ "$#" -eq 1]
#then
#echo 'SYNOPSIS:./createfile.sh '
#exit
#fi
if[ -a "$1" ]
then
echo "file $1 is exists. pless input other filename"
exit 1
elif [ -d "$1" ]
then
echo "file $1 is directory. pless input other filename"
exit 2
#创建脚本文件
elif [ ".sh" == "$Sh" ]
then
cat >$1
#!/bin/bash
#description:
#version:
#author: wukui
#license:GPL
EOF
Date=$(date +%F-%H:%M)
echo "#date:$Date">>$1
else
touch $1
exit
fi
# 判断是否为bash脚本类型文件,如果是则打开并定位到最后一行
if [ 'shell' == `file $1 | cut -d' ' -f3` ]
then
vim + $1
else
exit
fi
#给脚本文件加执行权限
if [ 'shell' == `file $1 | cut -d' ' -f3` ]
then
if ! [ -x "$1" ]
then
echo "chmod +x $1"
chmod u+x $1 &> /dev/null
fi
fi
#检查语法,如果有问题,用vim打开并定位到出现问题的行
if [ 'shell' == `file $1 | cut -d' ' -f3` ]
then
if ! `bash -n $1`
then
touch aaaaaaaaaa
bash -n $1 &> aaaaaaaaaa
Line=$(cut -d: -f2 aaaaaaaaaa | cut -d' ' -f3 | sort -u)
while [ -n "$Line"]
do
vim +$Line $1
bash -n $1 &> aaaaaaaaaa
Line=$(cut -d: -f2 aaaaaaaaaa | cut -d' ' -f3 | sort -u)
done
else
echo "very good"
exit
fi
fi
rm -f aaaaaaaaaa
页:
[1]