V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
Distributions
Ubuntu
Fedora
CentOS
中文资源站
网易开源镜像站
lizhengbo
V2EX  ›  Linux

鸟哥的这个案例执行不正确啊

  •  
  •   lizhengbo · 2022-02-27 18:59:10 +08:00 · 3512 次点击
    这是一个创建于 800 天前的主题,其中的信息可能已经有所发展或是发生改变。
    [dmtsai@study bin]$ vim userid.sh
    #!/bin/bash
    # Program
    # Use id, finger command to check system account's information.
    # History
    # 2015/07/17 VBird first release
    PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
    export PATH
    users=$( cut -d ':' -f1 /etc/passwd ) # 撷取帐号名称
    for username in ${users} # 开始循环进行!
    do
    id ${username}
    done

    ------------------------------------------------------------

    执行结果

    uid=0(root) gid=0(root) groups=0(root)
    uid=0(root) gid=0(root) groups=0(root)
    uid=0(root) gid=0(root) groups=0(root)
    uid=0(root) gid=0(root) groups=0(root)


    ------------------------------------------------------------
    cut -d ':' -f1 /etc/passwd 执行结果
    root
    bin
    daemon
    adm
    lp
    sync
    shutdown
    halt
    mail
    operator
    games
    ftp
    nobody
    systemd-network
    dbus
    polkitd
    libstoragemgmt
    rpc
    ntp
    abrt
    sshd
    postfix
    chrony
    tcpdump
    syslog
    lighthouse

    怎么改成展开正确
    5 条回复    2022-03-03 11:35:02 +08:00
    lizhengbo
        1
    lizhengbo  
    OP
       2022-02-27 19:09:42 +08:00
    抱歉,眼挫,把
    for username in ${users} # 开始循环进行!

    花括号,打成小括号()了
    waiaan
        2
    waiaan  
       2022-02-28 09:13:25 +08:00
    是什么书?
    Loku
        3
    Loku  
       2022-02-28 09:30:22 +08:00
    @waiaan 鸟哥的 Linux 私房菜
    ruanimal
        4
    ruanimal  
       2022-02-28 15:10:25 +08:00
    鸟哥的书基本上过时了,不太推荐
    lizhengbo
        5
    lizhengbo  
    OP
       2022-03-03 11:35:02 +08:00
    @ruanimal 还行,小白入门~
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5662 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 32ms · UTC 09:26 · PVG 17:26 · LAX 02:26 · JFK 05:26
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.