# ENV shows partial environment only

**URL:** <https://www.ruby-forum.com/t/env-shows-partial-environment-only/71054>\
**Category:** Ruby\
**Created:** [October 5, 2006, 12:59am UTC](https://www.ruby-forum.com/t/env-shows-partial-environment-only/71054 "2006-10-05T00:59:27Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b77776/32.png) [@rue](https://www.ruby-forum.com/u/rue)\
**Post date:** [October 5, 2006, 12:59am UTC](https://www.ruby-forum.com/t/env-shows-partial-environment-only/71054/1 "2006-10-05T00:59:27Z")

</div>

Hi!

It seems that Ruby is not picking up the complete environment  
to be accessible through ENV–and I seem to recall this is by  
design. Cursory poking-around in {hash,ruby,eval}.c did not  
reveal anything particularly enlightening. Could someone shed  
light on this if it indeed is done intentionally by Ruby and  
not due to some strangeness in the C env functions?

An example session:

18:28:43 ruerue@yawn \> ruby -v  
ruby 1.8.5 (2006-08-25) [amd64-freebsd6]

18:28:51 ruerue@yawn \> set | ruby -e ‘p ARGF.readlines.map {|l|  
l.split("=").first if l =~ /^[A-Z]/}.compact’

[“BASH”, “BASH\_ARGC”, “BASH\_ARGV”, “BASH\_LINENO”, “BASH\_SOURCE”,  
“BASH\_VERSINFO”, “BASH\_VERSION”, “BLOCKSIZE”, “COLUMNS”, “DIRSTACK”,  
“DISPLAY”, “EDITOR”, “EUID”, “FTP\_PASSIVE\_MODE”, “GROUPS”, “HISTFILE”,  
“HISTFILESIZE”, “HISTSIZE”, “HOME”, “HOSTNAME”, “HOSTTYPE”, “IFS”,  
“LINES”, “LOGNAME”, “MACHTYPE”, “MAIL”, “MAILCHECK”, “OPTERR”, “OPTIND”,  
“OSTYPE”, “PATH”, “PIPESTATUS”, “PPID”, “PR\_BROWN”, “PR\_CLEAR”,  
“PR\_LTGREY”, “PS1”, “PS2”, “PS4”, “PWD”, “RS\_EMAIL”, “RS\_NAME”, “SHELL”,  
“SHELLOPTS”, “SHLVL”, “TERM”, “TERMCAP”, “UID”, “USER”, “WINDOWID”,  
“XAUTHORITY”, “XTERM\_SHELL”, “XTERM\_VERSION”]

18:28:54 ruerue@yawn \> ruby -e ‘p ENV.keys’

[“SHELL”, “TERM”, “WINDOWID”, “XTERM\_SHELL”, “RS\_NAME”, “USER”,  
“TERMCAP”, “FTP\_PASSIVE\_MODE”, “PATH”, “MAIL”, “BLOCKSIZE”, “PWD”,  
“EDITOR”, “XTERM\_VERSION”, “HOME”, “SHLVL”, “LOGNAME”, “RS\_EMAIL”,  
“DISPLAY”, “XAUTHORITY”, “\_”]

---

<div class="post-metadata">

**Author:** ![rue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b77776/32.png) [@rue](https://www.ruby-forum.com/u/rue)\
**Post date:** [October 5, 2006, 1:25am UTC](https://www.ruby-forum.com/t/env-shows-partial-environment-only/71054/2 "2006-10-05T01:25:28Z")

</div>

On Thu, Oct 05, 2006 at 07:57:43AM +0900, Eero S. wrote:

> “LINES”, “LOGNAME”, “MACHTYPE”, “MAIL”, “MAILCHECK”, “OPTERR”, “OPTIND”,  
> “DISPLAY”, “XAUTHORITY”, “\_”]  
> Are you sure all those variables are “exported”? (For instance, I  
> seriously doubt IFS is ever exported by a sane shell unless you  
> explicitly tell it to do so.)

---

<div class="post-metadata">

**Author:** ![rue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b77776/32.png) [@rue](https://www.ruby-forum.com/u/rue)\
**Post date:** [October 5, 2006, 1:31am UTC](https://www.ruby-forum.com/t/env-shows-partial-environment-only/71054/3 "2006-10-05T01:31:30Z")

</div>

Ruby’s ENV hash contains environment variables as returned by ‘env’,  
not ‘set’, i.e.:

# env

# ruby -e ‘puts ENV.keys’

produce exact same lists.

Mike D.  
[http://www.rubywizards.com](http://www.rubywizards.com)

---

<div class="post-metadata">

**Author:** ![rue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b77776/32.png) [@rue](https://www.ruby-forum.com/u/rue)\
**Post date:** [October 5, 2006, 7:51pm UTC](https://www.ruby-forum.com/t/env-shows-partial-environment-only/71054/4 "2006-10-05T19:51:24Z")

</div>

removed\_email\_address@domain.invalid wrote:

> > “DISPLAY”, “EDITOR”, “EUID”, “FTP\_PASSIVE\_MODE”, “GROUPS”, “HISTFILE”,  
> > “TERMCAP”, “FTP\_PASSIVE\_MODE”, “PATH”, “MAIL”, “BLOCKSIZE”, “PWD”,  
> > harp:~ \> sh
> 
> harp:~ \> echo $FOO  
> ENV\_BAR

You’re using Bash/ksh syntax, but just so you know, the greater-than  
symbol (\>) is usually reserved to mean csh or tcsh. $ is the canonical  
non-root bash prompt. Switching them up makes examples like this one a  
little confusing, and can be frustrating when you have to use someone  
else’s machine for a second (e.g. to provide tech support through a VNC  
session) and some commands fail for no apparent reason.

---

<div class="post-metadata">

**Author:** ![rue](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/b77776/32.png) [@rue](https://www.ruby-forum.com/u/rue)\
**Post date:** [October 5, 2006, 7:23am UTC](https://www.ruby-forum.com/t/env-shows-partial-environment-only/71054/5 "2006-10-05T07:23:53Z")

</div>

On Thu, 5 Oct 2006, Eero S. wrote:

> “LINES”, “LOGNAME”, “MACHTYPE”, “MAIL”, “MAILCHECK”, “OPTERR”, “OPTIND”,  
> “DISPLAY”, “XAUTHORITY”, “\_”]  
> it’s been a while, but are you confusing shell vars with env vars? i  
> think  
> ‘set’ only reports the former:

harp:~ \> export FOO=ENV\_BAR

harp:~ \> set FOO=SHELL\_BAR

harp:~ \> sh

harp:~ \> echo $FOO  
ENV\_BAR

regards.

-a
