Unix $USER and $LOGNAME environment variables


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Unix $USER and $LOGNAME environment variables
# 1  
Old 01-19-2011
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.
# 2  
Old 01-19-2011
Put below codes in one script, and test by cronjob. You will see the difference.

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

# 3  
Old 01-19-2011
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.
# 4  
Old 01-19-2011
Code:
# echo $LOGNAME
root
# echo $USER
root
# su myuser
%echo $LOGNAME
root
%echo $USER
myuser
%

# 5  
Old 01-19-2011
Question

Quote:
Originally Posted by danmero
Code:
# 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' ?
# 6  
Old 01-19-2011
Quote:
Originally Posted by rdcwayx
Put below codes in one script, and test by cronjob. You will see the difference.

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

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

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

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


Quote:
Originally Posted by danmero
Code:
# echo $LOGNAME
root
# echo $USER
root
# su myuser
%echo $LOGNAME
root
%echo $USER
myuser
%

Yes, I am also getting the same results as like freakygs
# 7  
Old 01-19-2011
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.
This User Gave Thanks to Perderabo For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

UNIX $USER and $LOGNAME environment variables

I have some comments about a previously closed topic whose name is the same as above Omitted from the discussion was the situation with a "sudo command or sudo within a script". There is an inconsistency between systems. On some systems $LOGNAME is invariant, on others, on RedHat sudo... (3 Replies)
Discussion started by: lsatenstein
3 Replies

2. Shell Programming and Scripting

Doing math using user defined input and system environment variables

Hi, I need some help to setup some environmental variables. for example...Get A -> userdefined/user input B -> a number. c -> system variable...for example $GETCONF PAGE_SIZE E = do some math using bc display a message "The value is E" setup the system/kernel paramter sysctl -p... (3 Replies)
Discussion started by: saravanapandi
3 Replies

3. Shell Programming and Scripting

Run script through cron with user environment variables

Hi everyone, I wrote a script that is supposed to be run by cron on a daily basis. It works just fine if I run it manually, but due to a lack of environment variables (which are available during my user session but not when cron runs the script) it keeps failing to run successfully. Here's the... (2 Replies)
Discussion started by: gacanepa
2 Replies

4. HP-UX

Environment Variables

Hi Experts, Need your help in understanding the commands to setup the environment variables in hp-ux. Beleive need to use either set,setenv or export. I am confused between above three options, when to use which option? On command line, I have tried both set and setenv but couldn't... (1 Reply)
Discussion started by: sai_2507
1 Replies

5. Shell Programming and Scripting

Using Datastage environment variables in Unix script

Hi All, I am using ETL tool Datastage and is installed on Linux environment. Few environment variables are set in datastage. Now my requirement is to use those environment variables in a unix script. Is there any option I can do it? Sugeestions from people working on datastage and linux... (1 Reply)
Discussion started by: bghosh
1 Replies

6. UNIX for Dummies Questions & Answers

Environment variables

why are all environment variables represented in a fixed format regardless of the shell you use? like $HOME $PATH etc (6 Replies)
Discussion started by: sravani
6 Replies

7. Shell Programming and Scripting

using environment variables

say i define an environment variable in a particular script (upgrade.sh). my script is upgarde.sh and it calls another script try.sh. will this environment variable be accessible to try.sh also. if not how to I make environment variables global so that they can be used by any script. (2 Replies)
Discussion started by: lassimanji
2 Replies

8. Shell Programming and Scripting

environment variables

Hi, If i have a variable set and exported in my pofile file will that variable be available in all shell scripts created. Thanks, Radhika. (3 Replies)
Discussion started by: radhika03
3 Replies

9. UNIX for Advanced & Expert Users

by using c++ how to set environment variables in unix

hi, I am writing c++ code in unix operating system.In that i need to set the environment variable in unix. suppose previously i have environment variable like path="something" now i need to change the path value to some othervalue . so that some other program will access that path value... (1 Reply)
Discussion started by: sada@123
1 Replies

10. UNIX for Dummies Questions & Answers

what is the use of Environment variables

what is the actual use of environment variables. I know only PS1, LOGNAME, PS2 variables what are the other variables & what is there use (2 Replies)
Discussion started by: indianguru
2 Replies
Login or Register to Ask a Question