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

后端 未结 5 1654
野趣味
野趣味 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条回答
  •  说谎
    说谎 (楼主)
    2021-01-01 00:43

    I did this because I didn't want to have to write a file or mix up my ruby code with this stuff:

    #!/usr/bin/env bash
    eval $(echo "$(cat .env) $1" | tr '\n' ' ')
    

    I put this in ~/bin/run_with_env.sh and then for example I can run:

    % run_with_env.sh "rails console"
    

提交回复
热议问题