Skip to content

Instantly share code, notes, and snippets.

@thinkerbot
Created May 6, 2009 05:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thinkerbot/107363 to your computer and use it in GitHub Desktop.
Save thinkerbot/107363 to your computer and use it in GitHub Desktop.
a check of ENV inheritance
# This script demonstrates that ENV variables are inherited
# in system calls. The printout (assuming VARIABLE is not
# set beforehand) is:
#
# % ruby env_inheritance.rb
# before:
# reset: blue
# system: blue
# popen: blue
# after: blue
#
puts "before: #{ENV["VARIABLE"]}"
ENV["VARIABLE"] = "blue"
puts "reset: #{ENV["VARIABLE"]}"
system %q{ruby -e 'puts "system: #{ENV["VARIABLE"]}"; ENV["VARIABLE"] = "green"'}
IO.popen %q{ruby -e 'puts "popen: #{ENV["VARIABLE"]}"; ENV["VARIABLE"] = "green"'} do |io|
puts io.read
end
puts "after: #{ENV["VARIABLE"]}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment