I (on mac osx) often use
export http_proxy=http://192.168.0.205:1099
to proxy http connection to get a highed download speed. To make things easy, I wrote a shell file named proxy.sh to do this:
#!/bin/sh
export http_proxy=http://192.168.0.205:1099
Before I downlaod, I execute proxy.sh shell command, but I found it did’t not come into effect.It lost http_proxy variable in current commnad window(terminal). I must type export command in current terminal,it will come into effect.
So I want to know what’s reason for this and a solution? thanks.
Running a shell script “normally” (with
proxy.shfor example) results in that running in a sub-process so that it cannot affect the environment of the parent process.Using
.orsourcewill run the shell script in the context of the current shell, so it will be able to affect the environment, using one of the following:Another possibility (if you’re using
bashat least) is to create an alias to do the work for you. You can use something like:so that you can then simply type
fasteron the command line and it will export that variable (in the context of the current shell).You could also allow for one-shot settings such as:
and then use:
which would translate into:
That’s a
bashway to set a variable for just the one invocation of a command.