0

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.

2 Answers 2

1

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"] = ""
Sign up to request clarification or add additional context in comments.

Comments

0
%x( echo 'hi' )

and to capture standard output in a variable

var = %x( echo 'hi' )

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.