${LOGNAME} vs. ${USER}

Tom H tomh0665 at gmail.com
Thu Jul 30 11:19:44 UTC 2015


On Thu, Jul 30, 2015 at 3:23 AM,  <silver.bullet at zoho.com> wrote:
> 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

Sure, using su and sudo changes things but that's not what the OP was
asking about - unless I misunderstood the question.




More information about the ubuntu-users mailing list