I've noticed that csh and tcsh both set this variable - in fact, it's
hardcoded right into the source. But ksh/bash do not. Linux, and
apparently AIX, *do* set this variable for all shells (although in
the profile/csh.login etc).
I can't find documentation describing the standards for this variable.
Anyone know its pedigree?
Essentially, I'm wondering if I should set it in /etc/profile, or in
the developer's own .profiles.
--
Brandon Hume - hume -> BOFH.Ca, http://WWW.BOFH.Ca/
|
|
0
|
|
|
|
Reply
|
hume
|
4/11/2007 1:57:58 PM |
|
hume.spamfilter@bofh.ca wrote:
> I've noticed that csh and tcsh both set this variable - in fact, it's
> hardcoded right into the source. But ksh/bash do not. Linux, and
> apparently AIX, *do* set this variable for all shells (although in
> the profile/csh.login etc).
>
> I can't find documentation describing the standards for this variable.
> Anyone know its pedigree?
>
Why do you assume that there IS a standard? There may be, but I'd say
there is some doubt about its acceptance, to say the least.
> Essentially, I'm wondering if I should set it in /etc/profile, or in
> the developer's own .profiles.
>
To what purpose?
|
|
0
|
|
|
|
Reply
|
Richard
|
4/11/2007 2:22:09 PM
|
|
hume.spamfilter@bofh.ca <hume.spamfilter@bofh.ca> wrote:
> I've noticed that csh and tcsh both set this variable - in fact, it's
> hardcoded right into the source. But ksh/bash do not. Linux, and
> apparently AIX, *do* set this variable for all shells (although in
> the profile/csh.login etc).
For Linux, the variable USER is automatically set. It's not
done in /etc/profile.
> Essentially, I'm wondering if I should set it in /etc/profile, or in
> the developer's own .profiles.
Why do you want to set it yourself? Even on Solaris 10 with
bash (from Blastwave), USER is automatically set.
--
Alexander Skwar
|
|
0
|
|
|
|
Reply
|
Alexander
|
4/11/2007 2:33:51 PM
|
|
Richard B. gilbert <rgilbert88@comcast.net> wrote:
> Why do you assume that there IS a standard? There may be, but I'd say
> there is some doubt about its acceptance, to say the least.
I didn't know if there was a standard. Thus, I asked.
>> Essentially, I'm wondering if I should set it in /etc/profile, or in
>> the developer's own .profiles.
> To what purpose?
To let their existing scripts, which they're porting from AIX, to work.
--
Brandon Hume - hume -> BOFH.Ca, http://WWW.BOFH.Ca/
|
|
0
|
|
|
|
Reply
|
hume
|
4/11/2007 2:44:47 PM
|
|
hume.spamfilter@bofh.ca wrote:
> Richard B. gilbert <rgilbert88@comcast.net> wrote:
>>> Essentially, I'm wondering if I should set it in /etc/profile, or in
>>> the developer's own .profiles.
>
>> To what purpose?
>
> To let their existing scripts, which they're porting from AIX, to work.
How about adding a quick check to their scripts? Something like:
if [ x$USER = x ]
then
USER=`whoami`
export USER
fi
It's not elegant, but it works.
Jens
|
|
0
|
|
|
|
Reply
|
j
|
4/11/2007 2:48:28 PM
|
|
On Apr 11, 9:57 am, hume.spamfil...@bofh.ca wrote:
> I can't find documentation describing the standards for this variable.
> Anyone know its pedigree?
http://www.opengroup.org/onlinepubs/007908799/xbd/envvar.html
The open group defines "LOGNAME" as:
LOGNAME
The system will initialise this variable at the time of login to be
the user's login name...
...
And "USER" is just an alias for "LOGNAME" (BSD vs SysV):
http://www.faqs.org/docs/artu/ch10s04.html
USER
Login name of the account under which this session is logged in
(BSD convention).
LOGNAME
Login name of the account under which this session is logged in
(System V convention).
> Essentially, I'm wondering if I should set it in /etc/profile, or in
> the developer's own .profiles.
Should not hurt to set it globally, I think it should be safe to set
$USER to the value of $LOGNAME, or just do a "whoami".
Rayson
>
> --
> Brandon Hume - hume -> BOFH.Ca,http://WWW.BOFH.Ca/
|
|
0
|
|
|
|
Reply
|
raysonlogin
|
4/11/2007 4:07:12 PM
|
|
In <evisfs$76t$1@news-lx.mobilcom.de> j.goerke@mobilcom.de writes:
>hume.spamfilter@bofh.ca wrote:
>> Richard B. gilbert <rgilbert88@comcast.net> wrote:
>>>> Essentially, I'm wondering if I should set it in /etc/profile, or in
>>>> the developer's own .profiles.
>>
>>> To what purpose?
>>
>> To let their existing scripts, which they're porting from AIX, to work.
>How about adding a quick check to their scripts? Something like:
>if [ x$USER = x ]
>then
> USER=`whoami`
> export USER
>fi
We have this in /etc/profile to provide compatibility:
USER=${USER:-$LOGNAME}
LOGNAME=${LOGNAME:-$USER}
--
-Gary Mills- -Unix Support- -U of M Academic Computing and Networking-
|
|
0
|
|
|
|
Reply
|
Gary
|
4/11/2007 4:59:02 PM
|
|
Alexander Skwar <alexander@skwar.name> wrote:
> For Linux, the variable USER is automatically set. It's not
> done in /etc/profile.
I disagree.
$ uname -o
GNU/Linux
$ grep USER= /etc/profile
USER="`id -un`"
But this is all pointlessly pedantic. It gets set, for all shells on Linux -
that's the important part.
> Why do you want to set it yourself? Even on Solaris 10 with
> bash (from Blastwave), USER is automatically set.
I want to set it myself because *it's not being set*. It doesn't matter
what Blastwave's bash does or does not do... they're using Solaris ksh,
because that's their standard development environment.
They're using ksh because they used ksh on AIX. And they're using $USER
because it was set on AIX, and now they're wondering why it isn't set on
Solaris, and so am I... since everybody else *does* set it.
PS: Incidentally...
# grep hume /etc/passwd
hume:x:100:10:Brandon Hume:/home/hume:/opt/csw/bin/bash
# su - hume
$ echo "X${USER}X"
XX
-bash-3.2$
--
Brandon Hume - hume -> BOFH.Ca, http://WWW.BOFH.Ca/
|
|
0
|
|
|
|
Reply
|
hume
|
4/11/2007 7:43:33 PM
|
|
raysonlogin@gmail.com <raysonlogin@gmail.com> wrote:
> On Apr 11, 9:57 am, hume.spamfil...@bofh.ca wrote:
>> I can't find documentation describing the standards for this variable.
>> Anyone know its pedigree?
>
> http://www.opengroup.org/onlinepubs/007908799/xbd/envvar.html
This is an old standard. The current one states about environment
variables:
http://www.opengroup.org/onlinepubs/009695399/basedefs/xbd_chap08.html
But your comment about LOGNAME/USER is still valid.
--
Daniel
|
|
0
|
|
|
|
Reply
|
Daniel
|
4/11/2007 8:57:40 PM
|
|
raysonlogin@gmail.com <raysonlogin@gmail.com> wrote:
> And "USER" is just an alias for "LOGNAME" (BSD vs SysV):
> http://www.faqs.org/docs/artu/ch10s04.html
Awesome, this is exactly what I was looking for. My own searches didn't
produce much. Oddly enough, "USER" is not a useful search term, even when
combined with all the others I could think of. :)
--
Brandon Hume - hume -> BOFH.Ca, http://WWW.BOFH.Ca/
|
|
0
|
|
|
|
Reply
|
hume
|
4/11/2007 10:39:08 PM
|
|
hume.spamfilter@bofh.ca <hume.spamfilter@bofh.ca> wrote:
> Alexander Skwar <alexander@skwar.name> wrote:
>> For Linux, the variable USER is automatically set. It's not
>> done in /etc/profile.
>
> I disagree.
>
> $ uname -o
> GNU/Linux
> $ grep USER= /etc/profile
> USER="`id -un`"
And now for Solaris:
root@winds06 ~ # find /etc -type f -exec grep USER= /dev/null {} +
/etc/init.d/apache: TC_USER=`egrep '^[ \t]*User[ \t]' $CONF_FILE | nawk '{print $2}'`
/etc/init.d/init.cssd:ORACLE_USER=oracle
/etc/rc0.d/K16apache: TC_USER=`egrep '^[ \t]*User[ \t]' $CONF_FILE | nawk '{print $2}'`
/etc/rc1.d/K16apache: TC_USER=`egrep '^[ \t]*User[ \t]' $CONF_FILE | nawk '{print $2}'`
/etc/rc2.d/K16apache: TC_USER=`egrep '^[ \t]*User[ \t]' $CONF_FILE | nawk '{print $2}'`
/etc/rc3.d/S50apache: TC_USER=`egrep '^[ \t]*User[ \t]' $CONF_FILE | nawk '{print $2}'`
/etc/rcS.d/K16apache: TC_USER=`egrep '^[ \t]*User[ \t]' $CONF_FILE | nawk '{print $2}'`
/etc/sfw/ser/ser_mysql.sh:ROUSER=serro
/etc/sfw/ser/ser_mysql.sh:SQL_USER="root"
/etc/sfw/ser/ser_mysql.sh: INITIAL_USER="INSERT INTO subscriber
/etc/sfw/ser/ser_mysql.sh: INITIAL_USER=""
root@winds06 ~ # uname -a
SunOS winds06 5.10 Generic_118833-36 sun4u sparc SUNW,Sun-Fire-V240
root@winds06 ~ # echo $USER
root
root@winds06 ~ # grep USER= ~/.profile
root@winds06 ~ # grep USER= ~/.bash*
This leads me to say, that you might be able to remove this
USER=... line from your /etc/profile, as it's not required.
At least not for bash.
> I want to set it myself because *it's not being set*.
Untrue statement. At least here, on my systems. And I haven't
done anything special to have USER be set.
> PS: Incidentally...
>
> # grep hume /etc/passwd
> hume:x:100:10:Brandon Hume:/home/hume:/opt/csw/bin/bash
> # su - hume
> $ echo "X${USER}X"
> XX
> -bash-3.2$
Strange.
Alexander Skwar
|
|
0
|
|
|
|
Reply
|
Alexander
|
4/12/2007 8:03:43 AM
|
|
Alexander Skwar <alexander@skwar.name> wrote:
> And now for Solaris:
.. Which shell
.. Logged in locally, via su, via ssh?
Most shells (besides csh, tcsh) *don't* set USER. /bin/login also only sets
LOGNAME.
sshd *does* set a USER environment variable, because by default sshd uses
its own replacement of /bin/login. You can force the use of /bin/login
(and disabling setting USER by sshd) by putting "uselogin yes" in
sshd_config (X11 fordwarding won't work then any more though).
--
Daniel
|
|
0
|
|
|
|
Reply
|
Daniel
|
4/12/2007 8:22:30 AM
|
|
Daniel Rock <v200715@deadcafe.de> wrote:
> Alexander Skwar <alexander@skwar.name> wrote:
>> And now for Solaris:
>
> . Which shell
bash
> . Logged in locally, via su, via ssh?
Via ssh
> sshd *does* set a USER environment variable, because by default sshd uses
> its own replacement of /bin/login. You can force the use of /bin/login
> (and disabling setting USER by sshd) by putting "uselogin yes" in
> sshd_config (X11 fordwarding won't work then any more though).
Thanks. Now the different behaviours are explained quite well.
Alexander Skwar
|
|
0
|
|
|
|
Reply
|
Alexander
|
4/12/2007 9:35:54 AM
|
|
· hume.spamfilter@bofh.ca <hume.spamfilter@bofh.ca>:
> Alexander Skwar <alexander@skwar.name> wrote:
>> For Linux, the variable USER is automatically set. It's not
>> done in /etc/profile.
>
> I disagree.
Fine. You've got the right to be wrong ;)
alexander@blattli ~ $ uname -o
GNU/Linux
alexander@blattli ~ $ sudo grep -r USER= /etc 2>/dev/null
/etc/java-config-2/current-system-vm/bin/java-rmi.cgi: -DREMOTE_USER="$REMOTE_USER" \
/etc/netscsid.conf:# If no USER= entry is present, only root is allowed to run rscsi.
/etc/netscsid.conf:# Each USER= entry adds the listed user to the users who may run rscsi
/etc/netscsid.conf:# USER= entries are checked with a pattern matcher. USER=* matches all users.
/etc/netscsid.conf:USER=rscsi
/etc/netscsid.conf:#USER=joerg
/etc/pcmcia/memory.opts: NO_FUSER=n
/etc/pcmcia/serial.opts: NO_FUSER=n
/etc/pcmcia/parport.opts: NO_FUSER=n
/etc/pcmcia/ide.opts: NO_FUSER=n
/etc/pcmcia/scsi.opts: NO_FUSER=n
/etc/pcmcia/network.opts: NO_FUSER=n
alexander@blattli ~ $ grep USER /etc/profile
if [ "$EUID" = "0" ] || [ "$USER" = "root" ] ; then
alexander@blattli ~ $ grep USER .bash_profile .bashrc
..bashrc: PROMPT_COMMAND='echo -ne "\033]0;${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\007"'
..bashrc: PROMPT_COMMAND='echo -ne "\033_${USER}@${HOSTNAME%%.*}:${PWD/$HOME/~}\033\\"'
> But this is all pointlessly pedantic. It gets set, for all shells on Linux -
> that's the important part.
Yep. And it gets set automatically.
>> Why do you want to set it yourself? Even on Solaris 10 with
>> bash (from Blastwave), USER is automatically set.
>
> I want to set it myself because *it's not being set*.
Strange. Here, it is set. Without "manual" intervention
in a configuration file, if we'd call /etc/profile a cfg
file.
> It doesn't matter
> what Blastwave's bash does or does not do... they're using Solaris ksh,
> because that's their standard development environment.
You were talking about bash. I don't know what ksh does or
not does.
> PS: Incidentally...
>
> # grep hume /etc/passwd
> hume:x:100:10:Brandon Hume:/home/hume:/opt/csw/bin/bash
> # su - hume
> $ echo "X${USER}X"
> XX
> -bash-3.2$
On what system? Linux? AIX? Solaris?
Alexander Skwar
--
If all else fails, lower your standards.
|
|
0
|
|
|
|
Reply
|
Alexander
|
4/12/2007 9:57:17 PM
|
|
hume.spamfilter@bofh.ca wrote:
> I've noticed that csh and tcsh both set this variable - in fact, it's
> hardcoded right into the source. But ksh/bash do not. Linux, and
> apparently AIX, *do* set this variable for all shells (although in
> the profile/csh.login etc).
>
> I can't find documentation describing the standards for this variable.
> Anyone know its pedigree?
>
> Essentially, I'm wondering if I should set it in /etc/profile, or in
> the developer's own .profiles.
>
Bottom line is LOGNAME is a documented standard, USER is for BSD
compatibility. When I really need a reliable value I use
${LOGNAME:-${USER:-`logname`}}
Note that whoami returns the euid name, logname returns the uid name and
thus is more aligned with LOGNAME. I.e. if you log in as joe and su to
frank, logname will say joe and whoami will say frank. Also whoami
itself is nonstandard while logname is in POSIX.
HT
|
|
0
|
|
|
|
Reply
|
Henry
|
4/13/2007 12:17:50 PM
|
|
|
14 Replies
432 Views
(page loaded in 0.132 seconds)
Similiar Articles: The "USER" environment variable - comp.unix.solarisI've noticed that csh and tcsh both set this variable - in fact, it's hardcoded right into the source. But ksh/bash do not. Linux, and apparently AI... how can I set another user's login environment variables in a ...I have a daemon written in c, which starts separate process with different user ID. I want those process to get particular user's environment variable... Setting Environment Variable for ssh ForwardX11 Session - comp ...Somehow, the executed program can't get the required environment variables. Setting ~/.ssh/environment does not help so I end up creating a script to execute the user ... Question about setting environment variables for ssh remote ...For example, ssh user@host modinfo would complain the command modinfo is not found on a remote Solaris host. Need to run ssh user@host /usr/sbin/modin... Finding environment variables usage - comp.unix.programmer ...The "USER" environment variable - comp.unix.solaris Use Environment Variables Like built-in task environment variables, custom task environment variables apply only to a ... Is there a way to modify the environment of a running process in ...Is there any way to change environment variable of a running process? Ex. ... > Is possible also for the user owner of the process? Yes. Andreas. How to store current matrix in a variable? - comp.graphics.api ...Hello I'm writing a program where the user can freely move in a 3D-environment. However, there is one thing that I haven't solved yet: the user's ori... Environment variables in an awk script - comp.lang.awkEnvironment variables in an awk script - comp ... the "awk -f" solution the user does not have to remember the whole path for the script (if his PATH environment variable ... get current user name? - comp.unix.programmerroot is defined by: getuid()==0 man getpw > I though about using the LOGNAME environment variable, but if a regular > user used su root, the environment variable still ... Crontab Variable - comp.unix.shellCrontab Variable - comp.unix.shell... USER) #1: Thu Mar 30 01:00:38 EST 2006 > root ... to set an environment variable ... I am measuring a latent variable from 7 ... how to access environmental variables from shell in makefile ...The "USER" environment variable - comp.unix.solaris how to access environmental variables from shell in makefile ... Accessing Environment Variables In a Makefile You can ... crontab - environmental variables (platform: solaris; shell: bash ...(cron jobs are not supposed to inherit environment from the user's login shell, if he ... The "USER" environment variable - comp.unix.solaris crontab - environmental variables ... PS1 prompt set prior to /etc/profile - comp.unix.solaris ...However, I know little about > NIS+ and I can't find where it can set user environment variables. > > Wayne What shell are you using? I dont think anything will pre ... how to set environment variable in solaris 10 - comp.unix.solaris ...how can I set another user's login environment variables in a ... how to set environment variable in solaris 10 - comp.unix.solaris ... Hi, I am new to Solaris and I am ... mailx and variables? - comp.unix.solaris... quotes and all.. > > Still , I get an error saying bob is an unknown user ... to "yes" in /usr ... svcadm enable ssh # ps -ef | grep ssh root ... ... environment variable ... Environment Variables - Microsoft Corporation: Software ...Every process has an environment block that contains a set of environment variables and their values. There are two types of environment variables: user ... User Environment Variables - Microsoft Corporation: Software ...Environment variables specify search paths for files, directories for temporary files, application-specific options, and other similar information. 7/24/2012 12:54:27 PM
|