Setting bash environment variables in Ruby

Ruby scripts can be great every day helpers. I recently run over a task in which I wanted to start an application that relied on exported variables. In Ruby one can easily do this via the ENV object.

ENV['ENV_VAR_NAME'] = "some/lib/path"

You can make this of course more dynamic by using the ARGV for command line arguments or config files. But I think you get the idea from the above example.

Please note that it is not possible under Ruby to export a variable to its parent process i.e. the caller shell with the example above. I do also not know of any way how that would be achieved.

Advertisements