How do I source environment variables for a command shell in a Ruby script?

后端 未结 5 1677
野趣味
野趣味 2021-01-01 00:32

I\'m trying to run some third party bash scripts from within my ruby program.

Before I can run them they require me to source a file. On the command line it all wor

5条回答
  •  萌比男神i
    2021-01-01 01:00

    Do this:

    $ source whatever.sh
    $ set > variables.txt
    

    And then in Ruby:

    File.readlines("variables.txt").each do |line|
      values = line.split("=")
      ENV[values[0]] = values[1]
    end
    

    After you've ran this, your environment should be good to go.

提交回复
热议问题