Sunday, May 5, 2024
19
rated 0 times [  19] [ 0]  / answers: 1 / hits: 23948  / 2 Years ago, thu, march 17, 2022, 8:24:47

When the echo $LOGNAME and logname commands run normally, I get identical results from them:


pandya@pandya-desktop:~$ echo $LOGNAME
pandya
pandya@pandya-desktop:~$ logname
pandya

Is there any difference between them?


More From » environment-variables

 Answers
5

From Environment variables:


$LOGNAME is same as $USER which gives



The name of the currently logged-in user. This variable is set by the
system. You probably shouldn't change its value manually.



From man logname:



logname - print user´s login name





Explained differently used by following example:


pandya@pandya-desktop:~$ sudo su
root@pandya-desktop:/home/pandya# echo $LOGNAME
root
root@pandya-desktop:/home/pandya# logname
pandya
root@pandya-desktop:/home/pandya# exit
exit
pandya@pandya-desktop:~$



Here you can see the difference after logging as root in a terminal,



  • $LOGNAME gives the name of the currently logged-in user in the terminal (i.e root)

  • Whereas logname prints the user's login name who logged in to the session (i.e. pandya)


[#24333] Friday, March 18, 2022, 2 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
mugustered

Total Points: 193
Total Questions: 123
Total Answers: 108

Location: Bermuda
Member since Wed, Mar 22, 2023
1 Year ago
;