How can I get the current user's username in Bash?

后端 未结 12 2041
名媛妹妹
名媛妹妹 2021-01-29 18:04

I am writing a program in Bash that needs to get the user\'s username.

I have heard of a thing called whoami, but I have no idea what it does or how to use it.

W

12条回答
  •  北荒
    北荒 (楼主)
    2021-01-29 18:28

    Two commands:

    1. id prints the user id along with the groups. Format: uid=usernumber(username) ...

    2. whoami gives the current user name

提交回复
热议问题