Re: $USER vs. $LOGNAME and the EnvironmentVariables wiki page
On 26/03/2024 02:48, Patrice Duroux wrote:
1. Using CodeSearch, it is not clear to me when to use one or the other.
Some additions to Greg's answer.
From (info "(libc) Standard-Environment")
https://www.gnu.org/software/libc/manual/html_node/Standard-Environment.html
25.4.2 Standard Environment Variables
LOGNAME
This is the name that the user used to log in. Since the value in
the environment can be tweaked arbitrarily, this is not a reliable
way to identify the user who is running a program; a function like
getlogin (see Identifying Who Logged In) is better for that purpose.
For most purposes, it is better to use LOGNAME, precisely because
this lets the user specify the value.
The following man page is explicitly linked from the wiki page
environ(7) § NOTES:
The HOME, LOGNAME, SHELL, and USER variables are set when the user is
changed via a session management interface, typically by a program such
as login(1) from a user database (such as passwd(5)). (Switching to the
root user using su(1) may result in a mixed environment where LOGNAME
and USER are retained from old user; see the su(1) manual page.)
2. Would it be nice if the EnvironmentVariables page were linked to a
new page named EnvironmentVariablesList (the same way as DotFiles and
DotFilesList)?
Do you think it would be a long and detailed enough list? At least some
variables should be discussed in a more specific context, e.g.
<https://wiki.debian.org/DefaultWebBrowser#BROWSER_environment_variable>.
For USER vs. LOGNAME I see nothing Debian-specific, but on the other
hand I can not suggest a better site. (I have not tried to search on
stackoverflow.)
Reply to: