SHELL腳本編程和文件軟件包管理工具

1、編寫腳本 createuser.sh,實現如下功能:使用一個用戶名做爲參數,如果 指定參數的用戶存在,就顯示其存在,否則添加之;顯示添加的用戶的id號等信息


[root@centos8 data]# vim createuser.sh
#!/bin/bash
# 
#*****************************************************
#Author:                lqf
#QQ:                    393833084
#Date:                  2021-01-09
#FileName:              createuser.sh
#URL:                   http://www.magedu.com
#Description:           The test script
#Copyright(c):          2021 All rights reserved
#******************************************************

set -ue

NAME=$1
id $NAME &> /dev/null && echo "$NAME is exist" || { useradd "$NAME";echo "$NAME is created";echo "id $NAME";id "$NAME"; }
[root@centos8 data]# chmod +x createuser.sh
[root@centos8 data]# ./createuser.sh lqf
lqf is exist
[root@centos8 data]# ./createuser.sh test
test is created
id test
uid=1001(test) gid=1001(test) groups=1001(test)

2、編寫生成腳本基本格式的腳本,包括作者,聯繫方式,版本,時間,描述等

[root@centos8 ~]# vim .vimrc

set ignorecase
set cursorline
set autoindent
autocmd BufNewFile *.sh exec ":cal SetTitle()"
func SetTitle()
        if expand("%:e")=='sh'
        call setline(1,"#!/bin/bash")
        call setline(2,"#")
        call setline(3,"#*****************************************************")
        call setline(4,"#Author:                lqf")
        call setline(5,"#QQ:                    393833084")
        call setline(6,"#Date:                  ".strftime("%Y-%m-%d"))
        call setline(7,"#FileName:              ".expand("%"))
        call setline(8,"#URL:                   http://www.magedu.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                                                                                                        

腳本格式結果如下圖
SHELL腳本編程和文件軟件包管理工具

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章