初学shell脚本,自动生成shell脚本头注释信息

回复 收藏

初学Shell大家在编写shell的时候,是不是每次都要手动填写(#! /bin/bash \n # discription: \n #Author:等等)!

是不是感觉每次写都觉得能不能省掉呢,其实我劝大家一定要养成良好的习惯。不要去省,但是我们可以写个shell脚本自动帮我们创建添加!

#! /bin/bash
##when you add a new shell script you can add this one in front of your filename, that's can help you add the discrible
##writen by JustinZh 2017-05-18

if [ ! "$1" ]; then
        ehco "Pls Input A New Filename!"
        exit 1
fi
if [ -f "$1" ]; then
        vim "$1"
        exit 2
fi
touch "$1"
echo "#! /bin/bash" >> "$1"
echo "#Discription:" >> "$1"
echo "#Author:$USER" >> "$1"
echo "#Version:1.0" >> "$1"
echo "#CreateTime:`date +%F' 'H%:M%:S% `" >> "$1"
vim "$1"

当然 创建完成之后,你在哪个目录下运行此命令,它就会在此目录创建下创建你的shell。但是必须每次都要输入全称,例如此shell 我定义为autoshell.sh  如果想要创建一个test.sh 如下:#autoshell.sh test.sh 然后我想到了把autoshell.sh直接搞个软链接在/bin/auto目录下,然后chmod +x autoshell.sh  下次我再次创建一个shell的时候就只需要#auto test2.sh即可!!!

2017-05-18 09:39 举报
已邀请:
0

ggangelo

赞同来自:

666

0

讯风

赞同来自:

7-1 7-1 7-1

0

zomi

赞同来自:

66666666学习了

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: