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
whoran 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 exitExamples
Print your user name
whoamixRefuse 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.logCompare with the user sudo runs as
whoamix; sudo whoamixPrint the user with a label
printfx 'user: %s\n' "$(whoamix)"Check which user a container runs as
docker run --rm gnux whoamixUse 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'Print the user in the portable gnux shell
gnux shell -c 'whoamix'Exit status
| Status | Meaning |
|---|---|
| 0 | success: every operand was processed |
| 1 | failure: 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