LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   export call in bash script (https://www.linuxquestions.org/questions/linux-software-2/export-call-in-bash-script-56875/)

Donald1000 04-26-2003 11:12 AM

export call in bash script
 
Hi,

ii wrote the following simple bash script, that should exort a sinple environment variable:
-----
#!/bin/bash
export http_proxy=http://14.15.16.17
-----
I made a chmod +x, but when i executed it, nothing happend. It does not set the path correctly!

does anyone know this probblem?

thanx for any help.

Crashed_Again 04-26-2003 11:44 AM

hmmm...well what are you trying to do exactly? If you do:

export http_proxy=http://14.15.16.17
echo $http_proxy

you should get:

http://14.15.16.17

of course that is temporary. If you want http_proxy to be perminentaly set to http://14.15.16.17 then you should add those lines to your .bashrc file.

pablob 04-26-2003 04:04 PM

Yes, because the "export" you do inside the script, only lives during the execution of the "bash" session.

acid_kewpie 04-26-2003 05:11 PM

so don't use any interpreter at all, no shebang line.

Donald1000 04-27-2003 01:23 PM

Thanks for your answers. But this is not what i mean. I do not want to set it permanently. When i log in my bash and make a "echo $http_proxy" i get nothing. (no entry) Thats OK, because no proxy was set at the beginning of the session. Now i execute the script i worte obove. But still the proxy was not set. Why? Do i have to put any other command in the script? I don't need it in the .bashrc - So why does it not work in my own script?

acid_kewpie 04-27-2003 02:16 PM

that's what i meant. the call to use bash invokes a new login session, as oposed to not having any reference to an interpreter, which will use the current environment.

mhearn 04-28-2003 08:56 AM

Type this instead

source myscript

problem solved (for that shell). You probably want to stick it in your /etc/profile script though

Mik 04-28-2003 09:32 AM

The standard way to run a script in the current shell process is to run it with a . in front of the script.

Ex.

. set_ip

This would ofcourse have the same effect as running 'source set_ip' as mentioned before.

Crashed_Again 04-28-2003 10:37 AM

How about this. Instead of writing a script for it you just make an alias for the export command. Add the following to your /etc/bashrc file:

alias proxy='export http_proxy=http://14.15.16.17 '

Now you can just type:

proxy

and the http_proxy variable will be set for you.

Donald1000 04-29-2003 06:12 AM

Thanks again! mhearn, i've tested it with the "source" command and it works. Great! Crashed_Again, i think your method works, too.

Pada 03-12-2009 08:03 PM

I know this is an ancient thread, but I've had the exact same issues when trying to use export http_proxy in a bash script.

My solution, use 'declare -x' instead of 'export'
Code:

#!/bin/bash

declare -x http_proxy="<proxy info here>"
declare -x ftp_proxy="<proxy info here>"



All times are GMT -5. The time now is 09:40 AM.