Reputation: 23
I have a script in Ruby and inside has to run a bash
command. This command is an export http_proxy = ""
and export https_proxy = ""
.
The problem is that I run the following, without running errors, but appears that doesn't make any change:
system "export http_proxy=''"
system "export https_proxy=''"
I created a file.sh
with this lines and if I run it in a terminal only works when run: source file.sh
or . file.sh
.
Could you please help me how I can run this commands in the Ruby script? It can be directly with the command lines or executing an .sh
file in the script.
Upvotes: 0
Views: 156
Reputation: 881113
When you run a separate process using system
, any changes made to the environment of that process affects that process only, and will disappear when the process exits.
That exactly why running file.sh
won't change your current shell since it runs it as a sub-shell, and the changes disappear when the process exits.
As you've already discovered, using source
or .
runs deoes affect the current shell but that's because it runs the script not as a sub-shell, but within the context of the current shell.
If you want to change the environment variables of the current Ruby script, you should look into ENV
, something like:
ENV["http_proxy"] = ""
ENV["https_proxy"] = ""
Upvotes: 1
Reputation: 589
%x( echo 'hi' )
and to capture standard output in a variable
var = %x( echo 'hi' )
Upvotes: 0