LOGNAME
Logname is a Unix-like command that prints the login name of the user who started the current login session. It is often used in shell scripts to determine the original user associated with a session, especially in environments where privilege escalation or user switching occurs. The command outputs a single line containing the login name, followed by a newline, and typically exits with status 0 on success or a nonzero status on failure.
Implementation and behavior vary by system. On many Unix-like systems, logname obtains the login name from the
Because logname reflects the login session rather than the effective user ID, its value may differ from
Typical usage is simple: logname. It is commonly included in scripts to preserve or verify the original