Skip to Content
gnux

whoamix

Print the user name associated with the current effective user ID.

Mirrors GNU whoami. Run it as whoamix, or as gnux whoamix.

Synopsis

whoamix [OPTION]...

GNU reference

Description

whoamix prints the name of the user the process runs as: the effective user, so inside sudo it prints root. It takes no operands. On Windows, where the account name is DOMAIN\user, only the user part is printed, as GNU whoami does under Cygwin and MSYS. If the user ID has no name, whoamix reports 'cannot find name for user ID N' and exits 1.

Permissions

Needs read access to the user database (/etc/passwd or the system's directory service) to turn the user ID into a name.

Use cases

  • Refusing to run a script as root, or insisting on it.
  • Naming per-user files, directories or caches in a portable way.
  • Recording who ran a job in a log line.
  • Checking which account a CI runner or container uses.
  • Getting the user name on Windows without USERNAME and on Unix without USER.

Flags

      --help      display this help and exit
      --version   output version information and exit

Examples

whoamix

Refuse to run as root

[ "$(whoamix)" = root ] && { echox 'do not run as root' >&2; exit 1; }

Create a per-user scratch directory

mkdirx -p "/tmp/$(whoamix)/cache"

Record who ran a job

echox "deployed by $(whoamix) on $(hostnamex)" >> deploy.log

Compare with the user sudo runs as

whoamix; sudo whoamix
printfx 'user: %s\n' "$(whoamix)"

Check which user a container runs as

docker run --rm gnux whoamix

Use the name in a file name

cpx notes.md "notes-$(whoamix).md"

Fail clearly when the user has no name (exit status 1)

whoamix || echox 'no user name for this ID'
gnux shell -c 'whoamix'

Exit status

StatusMeaning
0success: every operand was processed
1failure: an operand could not be processed (diagnosed on standard error), or a command-line mistake

Help in the terminal

whoamix --help                # options, first examples, exit status
gnux help whoamix             # this page: the full manual
gnux help whoamix --OPTION    # one option in depth, with its examples

See also

On this page