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脚本编程和文件软件包管理工具

标签: SHELL, NAME, 软件包, 管理工具, sh, call, setline, createuser

相关文章推荐

添加新评论,含*的栏目为必填