HOSTNAME environment variable on Linux
Posted
by infogrind
on Super User
See other posts from Super User
or by infogrind
Published on 2010-04-19T08:16:09Z
Indexed on
2010/04/19
8:23 UTC
Read the original article
Hit count: 217
On my Linux box (Gentoo Linux 2.6.31 to be specific) I have noticed that the HOSTNAME environment variable is available in my shell, but not in scripts. For example,
$ echo $HOSTNAME
returns
xxxxxxxx.com,
but
$ ruby -e 'puts ENV["HOSTNAME"]'
returns
nil
On the other hand, the USER environment variable, for instance, is available both in the shell and in scripts.
I have noticed that USER appears in the list of environment variables that appears when I type
export
i.e.,
declare -x USER="infogrind"
but HOSTNAME doesn't. I suspect the issue has something to do with that.
My questions: 1) how can I make HOSTNAME available in scripts, and 2) for my better understanding, where is this variable initially set, and why is it not "exported"?
© Super User or respective owner