怎样给你的shell脚本自动加上信息

1.什么是shell

shell是操作系统中的一个软件,包含在linux内核的外面,为用户和内核之间的交互提供了一个接口。系统中的命令用shell去解释shell接收系统回应的输出并显示其到屏幕中。
bash=GNU Bourne-Again Shell

2.什么是shell脚本

脚本是一种解释型语言
用shell脚本保存执行的动作
用脚本判定命令的执行条件
用脚本来实现动作的批量执行

3.执行脚本的方式

(1)chmod +x ip-show.sh
     ip_show.sh      绝对路径
(2)sh ip_show.sh   直接执行

4.在脚本中添加关于该脚本的信息说明

(1)我们可以选择在每次写脚本之前,都重新写一次信息说明,不过这样比较麻烦

(2)可以选择一种较为快捷的方式,按下快捷键就可添加一些固定的信息

     vim /etc/vimrc
       map <F4> ms:call MESS()<cr>'s   (打开要编辑的脚本按下F4,调用MESS函数,即可添加这些信息)
       func MESS()
           call append(0,"######################")
           call append(1,"#Author:          jay".("#"))
           call append(2,"#Version:            ".("#"))
           call append(3,"#Telephone:          ".("#"))
           call append(4,"#Date:     ".strftime("%Y-%m-%d").("#"))
           call append(5,"#Description         ".("#"))
           call append(6,"######################")
           call append(7,"                    ".(""))
           call append(8,"#!/bin/bash")
        endfunc

(3)更为快捷的方式是,在打开一个新的以.sh结尾的文件时,自动添加这些信息

    vim /etc/vimrc
       autocmd BufNewFile *.sh exec ":call MESS()"(自动调用MESS函数给新的并以.sh结尾的文件添加这些信息)
       func MESS()
           call append(0,"######################")
           call append(1,"#Author:          jay".("#"))
           call append(2,"#Version:            ".("#"))
           call append(3,"#Telephone:          ".("#"))
           call append(4,"#Date:     ".strftime("%Y-%m-%d").("#"))
           call append(5,"#Description         ".("#"))
           call append(6,"######################")
           call append(7,"                    ".(""))
           call append(8,"#!/bin/bash")
        endfunc

这里写图片描述

这里写图片描述

猜你喜欢

转载自blog.csdn.net/jay_youth/article/details/80657678