I'm using ruby 1.8.7 patch 249. Is the following the best/only way to pass environment variables to a shell command that I need to execute from my ruby program?
fork do ENV['A'] = 'A' exec "/bin/bash -c 'echo $A'" end Process.wait
There is a really easy way:
system({"MYVAR" => "42"}, "echo $MYVAR")
All credit for this goes to Avdi: https://stackoverflow.com/a/8301399/171933
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With