SHELL创建脚本工具
2014-07-13 14:57
513 查看
每次新建一个脚本的时候都,都要在脚本前面加上#!/bin/bash等一些固定格式的文本,这个bash脚本创建脚本可以自动添加解释器为bash、日期作者等一些信息。并且在创建完成后自动检查语法是否有错误,如果有错误它会帮你用vim打开,并且定位到出现语法问题的行。如果语法有错误,会强制不让你退出。要退出按ctrl+c键。给如果创建是的bash脚本文件,会给此文件加执行权限。
使用方法:在此脚本后面跟上你要创建的文件名,文件名要以.sh结尾,否则不会当作脚本文件。
#./create.sh new_file.sh
附件用windows记事本打开可能会不换行。这是因linux与windoows换行符不同造成的。
使用方法:在此脚本后面跟上你要创建的文件名,文件名要以.sh结尾,否则不会当作脚本文件。
#./create.sh new_file.sh
#!/bin/bash # # # # 判断文件是否存在 Sh=$(echo $1 | grep -o '.sh$') #if ! [ "$#" -eq 1 ] #then # echo 'SYNOPSIS:./createfile.sh <FileName>' # 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 << EOF >>$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
附件用windows记事本打开可能会不换行。这是因linux与windoows换行符不同造成的。
相关文章推荐
- Shell脚本编程实战一:创建按天备份的脚本工具
- shell脚本批量创建用户
- 本地yum源的创建,以及无人值守shell脚本安装.(DVD版)
- Monkeyrunner 写脚本的技巧(shell 命令,文件操作)---关键点,python创建以时间命名的文件夹
- 10个工具让你的 shell 脚本更强大
- [shell]采用shc工具加密Shell脚本
- shell脚本查看 创建目录
- 用c++创建一个Linux上的Daemon程序,含SHELL管理脚本(二)
- 查看网卡流量shell脚本工具:network_top.sh
- shell脚本编程:Linux的自动化逻辑卷创建脚本
- 使用 shell 脚本创建好的图形应用程序
- 本地yum源的创建,以及无人值守shell脚本安装.(DVD版)
- 对话UNIX:使用shell脚本创建好的图形应用程序
- 本地yum源的创建,以及自动shell脚本安装.(DVD版)
- shell时间,shell创建文件,linux shell编写以日期时间为文件名的脚本学习笔记 (转)
- 用Shell脚本创建批量用户
- Shell 脚本加密工具shc
- mongodb集群脚本工具(shell)
- linux shell + expect:批量scp脚本工具
- 用c++创建一个Linux上的Daemon程序,含SHELL管理脚本(一)