From: Rob Biedenharn Date: 2009-08-08T01:05:11+09:00 Subject: Re: how to "source" a file? On Aug 7, 2009, at 11:00 AM, Ilan Berci wrote: > Ken Feng wrote: >> I have a bash file ~/.myenv that contains environmental variables >> like: >> >> export EDITOR=vi >> export FOO=bar >> ... >> >> How do I source this file from within a ruby script that starts like? >> >> #!/usr/bin/ruby >> >> I could source the file in bash before running the ruby script, but I >> prefer that the script do it, in case the user forgets. >> >> Thx. >> >> -Ken > > `source ~/.myenv` > > at work.. NOT TESTED.. guess > > ilan Nope! That will set those variables in the child process and any of its children, but they'll go away and have no effect on your ruby process. Your best bet is to warn the user if you are using defaults and tell him/her/yourself to fix it. unless ENV['EDITOR'] ENV['EDITOR'] = 'vi' puts "Environment has no EDITOR using '#{ENV['EDITOR']}'" puts "Did you mean to?: source ~/.myenv" end You could also exit without doing anything if the value has no acceptable default. -Rob Rob Biedenharn http://agileconsultingllc.com Rob@AgileConsultingLLC.com