I am trying to understand the differences between logname and LOGNAME from Difference between logname and $LOGNAME and https://askubuntu.com/questions/490620/difference-between-logname-and-logname
On Lubuntu 18.04, why did I get logname: no login name?
t@ocean:/t/t/bkg$ echo $LOGNAME
t
t@ocean:/t/t/bkg$ logname
logname: no login name
t@ocean:/t/t/bkg$ su t
Password:
t@ocean:/t/t/bkg$ logname
logname: no login name
$ echo $?
1
t@ocean:/t/t/bkg$ cat /var/run/utmp
~~~reboot4.15.0-22-generic��[8Jtty1tty1LOGINJ��[�!�tty7:0t:0��[��5~~~runlevel4.15.0-22-generic��[
t@ocean:/t/t/bkg$ sudo su
[sudo] password for t:
root@ocean:/tmp/test/bkg# logname
logname: no login name
root@ocean:/tmp/test/bkg# echo $LOGNAME
root
What is logname supposed to output?
Thanks.
From man logname:
logname - print user´s login name
Print the name of the current user.
To address the comments:
$ cat /proc/self/loginuid
4294967295
t@ocean:/t/t/bkg$ grep ":$(id -u):" /etc/passwd
t:x:1000:1000:t,,,:/home/t:/bin/bash
t@ocean:/t/t/bkg$ tty
/dev/pts/8
t@ocean:/t/t/bkg$ w
17:52:08 up 5 days, 6:28, 1 user, load average: 0.39, 0.29, 0.28
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
t tty7 :0 Wed11 5days 1:47m 6.33s /usr/bin/lxsession -s Lubuntu -e LXDE
Mark suspected the cause is that my lxterminal doesn't add an entry to utmp.
Pandya: Oh. Seems a bug with entry as you've concluded.