Unix $USER and $LOGNAME environment variables

Hi,

I am wondering what is the difference between the USER and LOGNAME environment variables, and under what situations would they be different?

I am using Ubuntu 8.04 32-bit and I do not have 'login' command to test it.

Put below codes in one script, and test by cronjob. You will see the difference.

echo " LOGNAME: "
echo $LOGNAME
echo "*********"
echo " USER: "
echo $USER
echo "*********"

Hey rdcwayx..

Could you please post the result as well, I work on a Production UNIX machine, and I don't have cron rights.
Even I am following this post...
I tried using su but both $LOGNAME and $USER values were same

Thanks.

# echo $LOGNAME
root
# echo $USER
root
# su myuser
%echo $LOGNAME
root
%echo $USER
myuser
%

after I did an 'su <username> I am getting same value for LOGNAME and USER...
Is this output specific to 'root' ?

When I ran it through crontab it is giving me below output.

LOGNAME:
ibrahim
*********
USER:

*********
Why USER is empty?

Yes, I am also getting the same results as like freakygs

Please post your exact version of unix when discussing this. If you're not sure run the command "uname -a" and post what it outputs.

LOGNAME is the original variable and tends to be used in System V Unix and its decendants. USER was introduced by BSD to replace LOGNAME. These days lots of versions of Unix provide both in an effort to please everybody. If both are present they should have the same value.

1 Like

Thank you Perderabo. I have already mentioned the details of my operating system in my first post. Anyway, I am using Ubuntu 8.04 (LTS) 32-bit