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. |
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. |
Yes, because the "export" you do inside the script, only lives during the execution of the "bash" session.
|
so don't use any interpreter at all, no shebang line.
|
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?
|
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.
|
Type this instead
source myscript problem solved (for that shell). You probably want to stick it in your /etc/profile script though |
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. |
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. |
Thanks again! mhearn, i've tested it with the "source" command and it works. Great! Crashed_Again, i think your method works, too.
|
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 |
All times are GMT -5. The time now is 09:40 AM. |