summaryrefslogtreecommitdiff
path: root/lib/Env.rb
blob: e52501f801d78d196a9626d065912a07f6511dc8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Env.rb -- imports environment variables as global variables
#
# Usage:
#
#  p $USER
#  $USER = "matz"
#  p ENV["USER"]

for k,v in ENV
  next unless /^[a-zA-Z][_a-zA-Z0-9]*/ =~ k
  eval <<EOS
  $#{k} = %q!#{v}!
  trace_var "$#{k}", proc{|v|
    ENV[%q!#{k}!] = v; 
    $#{k} = %q!#{v}!
    if v == nil
      untrace_var "$#{k}"
    end
  }
EOS
end

p $TERM
$TERM = nil
p $TERM
p ENV["TERM"]
$TERM = "foo"
p ENV["TERM"]