首先加一個(gè)通用代碼乱灵,用vim時(shí)塑崖,當(dāng)后綴名為"*.sh"時(shí),自動(dòng)添加作者痛倚,聯(lián)系方式规婆,版本,時(shí)間蝉稳,描述等信息抒蚜。我們可以在
用戶家目錄下.vimrc或者全局配置文件/etc/vimrc中加入以下代碼:
set tabstop=4
set softtabstop=4
set shiftwidth=4
set expandtab
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: 自己改")
call setline(5, "#QQ: 自己改")
call setline(6, "#Date: ".strftime("%Y-%m-%d"
))
call setline(7, "#FileName: ".expand("%"))
call setline(8, "#URL: 自己改
")
call setline(9, "#Description: The test script")
call setline(10, "#Copyritght (C): ".strftime("%Y")." ALL rights
reserved")
call setline(11, "#==========================================================
======")
call setline(12,"")
endif
endfunc
ok,打開(kāi)vim編輯器,編寫(xiě)第一個(gè)shell腳本createuser.sh
功能如下:
使用一個(gè)用戶名做為參數(shù)耘戚,如果 指定參數(shù)的用戶存在嗡髓,就顯示其存在,否則添加之;顯示添加的用戶的id號(hào)等 信息
#!/bin/bash
#
#================================================================
#Author: zouybi
#QQ: 273838882
#Date: 2020-02-29
#FileName: createuser.sh
#URL: http://www.和諧.com
#Description: The test script
#Copyritght (C): 2020 ALL rights reserved
#================================================================
read -p "give me a username:" userNAME
if id -u $userNAME &> /dev/null;then
echo "user exists"
echo "$userNAME info is:`id $userNAME`"
else
echo "user does not exist,to start create"
useradd $userNAME && echo "$userNAME info is:`id $userNAME`"
fi
#執(zhí)行結(jié)果
[root@localhost data]# chmod +x createuser.sh
[root@localhost data]# ./createuser.sh
give me a username:wang
user does not exist,to start create
wang info is:uid=1001(wang) gid=1001(wang) groups=1001(wang)
[root@localhost data]# ./createuser.sh
give me a username:wang
user exists
wang info is:uid=1001(wang) gid=1001(wang) groups=1001(wang)