${LOGNAME} vs. ${USER}

silver.bullet at zoho.com silver.bullet at zoho.com
Thu Jul 30 10:23:29 UTC 2015


On Thu, 30 Jul 2015 02:54:02 -0700, Tom H wrote:
>On Sun, Jul 12, 2015 at 5:32 AM, Johnny Rosenberg wrote:
>> In my case, both ${LOGNAME} and ${USER} happens to be the same, so
>> both work, but I guess that's not always true, is it?
>
>They're set to tbe the same by login. LOGNAME is a SYSV variable and
>USER is BSD variable but they're both set on Ubuntu and FreeBSD.

I'm booted to Arch Linux at the moment, but it shouldn't differ
from Ubuntu. The output of the id command differs, it's the only way for
scripts to test for root privilges, if the install is set up with a
root account. Oops, resp. $EUID seems to work for this purpose too.

What you need for your usage, depends on what you want to achieve.

Take a look at the differences, especial how it differs after running
sudo or su.

$ echo $LOGNAME $USER $(id -un) $EUID $(id -u)
rocketmouse rocketmouse rocketmouse 1000 1000

$ sudo -i
# echo $LOGNAME $USER $(id -un) $EUID $(id -u)
root root root 0 0

$ su 
# echo $LOGNAME $USER $(id -un) $EUID $(id -u)
rocketmouse rocketmouse root 0 0

Regards,
Ralf





More information about the ubuntu-users mailing list