zoukankan      html  css  js  c++  java
  • shell脚本学习-练习写一个脚本1

    # 1.依次展示/etc/passwd中的用户名和UID。格式如:Hello,$USER,your UID is $UID.

    # 2.统计一个有多少个用户

    #!/bin/bash
    #Program Description:   
    #Author: Created by ctu_lzq 
    #Date: 2018/11/15
    FILE="/etc/passwd"
    LINES=`cat $FILE |wc -l`
    #for i in `seq 1 $LINES`;
    for ((i=1;i<=$LINES;i++));
    do
        userlist=`sed -n "$i""p" $FILE|awk -F: '{print $1}'`
        uidlist=`sed -n "$i""p" $FILE|awk -F: '{print $3}'`
        echo "Hello,$userlist,your UID is $uidlist"
    done
    echo  "there are $LINES users"
    结果如:
    [root@study learnshell]# bash test.sh Hello,root,your UID is 0 Hello,bin,your UID is 1 Hello,daemon,your UID is 2 Hello,adm,your UID is 3 Hello,lp,your UID is 4 Hello,sync,your UID is 5 Hello,shutdown,your UID is 6 Hello,halt,your UID is 7 Hello,mail,your UID is 8 Hello,uucp,your UID is 10 Hello,operator,your UID is 11 Hello,games,your UID is 12 Hello,gopher,your UID is 13 Hello,ftp,your UID is 14 Hello,nobody,your UID is 99 Hello,dbus,your UID is 81 Hello,usbmuxd,your UID is 113 Hello,rpc,your UID is 32 Hello,rtkit,your UID is 499 Hello,avahi-autoipd,your UID is 170 Hello,vcsa,your UID is 69 Hello,abrt,your UID is 173 Hello,rpcuser,your UID is 29 Hello,nfsnobody,your UID is 65534 Hello,haldaemon,your UID is 68 Hello,ntp,your UID is 38 Hello,apache,your UID is 48 Hello,saslauth,your UID is 498 Hello,postfix,your UID is 89 Hello,gdm,your UID is 42 Hello,pulse,your UID is 497 Hello,sshd,your UID is 74 Hello,tcpdump,your UID is 72 Hello,mysql,your UID is 27 Hello,nginx,your UID is 496

      

  • 相关阅读:
    列表与数组 Perl入门第三章
    北京地区-医类汇总
    via/route blockage/size blockage/wire/pin guide/pin blockage/partition
    dbGet(三)
    dbGet(二.一)hinst
    微服务是什么?
    Docker入门 四 Swarms集群
    Docker入门 三 用服务来扩展和负载均衡你的应用
    Linux2.2路径、删除目录及文件
    Linux2.1系统目录结构、ls、文件类型、alias
  • 原文地址:https://www.cnblogs.com/ctulzq/p/9963925.html
Copyright © 2011-2022 走看看