代码之家  ›  专栏  ›  技术社区  ›  N.Ali

脚本shell:告诉用户登录多少次

  •  1
  • N.Ali  · 技术社区  · 9 年前

    count=$(who | grep $user | wc -l)
    echo "$user is logged on $count times."
    
    but it gives me the following output:
     is logged on      0 times.
    

    我错过了什么?

    1 回复  |  直到 9 年前
        1
  •  3
  •   Elliott Frisch    9 年前

    您正在使用 $user $USER 喜欢

    count=$(who | grep $USER | wc -l)
    echo "$USER is logged on $count times."
    

    我明白了

    efrisch is logged on 4 times.
    

    printf 喜欢

    printf "%s is logged on %s times.\n" $USER $(who | grep $USER | wc -l)