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.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: