Linux 之shell脚本设置开头固定格式

Linux 之shell脚本设置开头固定格式


每次进入shell都要设置开头,很麻烦,现修改vim配置文件即可。

[root@node01 ~]vim .vimrc 

将下列内容复制进文件

set ignorecase                                                                                                             
set cursorline
set autoindent
autocmd BufNewFile *.sh exec ":call SetTitle()"
func SetTitle()
         if expand("%:e") == 'sh'
         call setline(1,"#!/bin/bash")
         call setline(2,"#")
         call setline(3,"#********************************************************************")
         call setline(4,"#Author:                XiaoMa")
         call setline(5,"#QQ:                    1060389294")
         call setline(6,"#Date:                  ".strftime("%Y-%m-%d"))
         call setline(7,"#FileName:             ".expand("%"))
         call setline(8,"#URL:                   http://www.baidu.com")
         call setline(9,"#Description:          The test script")
         call setline(10,"#Copyright (C):        ".strftime("%Y")." All rights reserved")
         call setline(11,"#********************************************************************")
         call setline(12,"")
         endif
endfunc
autocmd BufNewFile * normal G

之后新建一个shell ,开头就会有固定的格式。
在这里插入图片描述
这是在root用户下的配置,切换到用户使用shell 可能还是什么都没有,不过一般都是用root用户进行机器的管理。
如果想在普通用户上,就需要把root目录下的.vimrc文件拷贝到用户家目录下
这里我以hadoop用户举例

[hadoop@node01 ~]sudo cp /root/.vimrc ./

不加sudo 没有权限进入root,这样就把文件复制过来了,再次创建文件就会出现默认的格式。

猜你喜欢

转载自blog.csdn.net/qq_43570528/article/details/109104865