LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 04-26-2003, 12:12 PM   #1
Donald1000
Member
 
Registered: Oct 2002
Location: Germany
Distribution: Debian, Non-Linux: Solaris, FreeBSD
Posts: 107

Rep: Reputation: 15
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.
 
Old 04-26-2003, 12:44 PM   #2
Crashed_Again
Senior Member
 
Registered: Dec 2002
Location: Atlantic City, NJ
Distribution: Ubuntu & Arch
Posts: 3,503

Rep: Reputation: 57
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.
 
Old 04-26-2003, 05:04 PM   #3
pablob
Member
 
Registered: Apr 2003
Location: Madrid
Distribution: RHAS, Kubuntu, Solaris, TRU64
Posts: 381

Rep: Reputation: 31
Yes, because the "export" you do inside the script, only lives during the execution of the "bash" session.
 
Old 04-26-2003, 06:11 PM   #4
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,414

Rep: Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967
so don't use any interpreter at all, no shebang line.
 
Old 04-27-2003, 02:23 PM   #5
Donald1000
Member
 
Registered: Oct 2002
Location: Germany
Distribution: Debian, Non-Linux: Solaris, FreeBSD
Posts: 107

Original Poster
Rep: Reputation: 15
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?
 
Old 04-27-2003, 03:16 PM   #6
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,414

Rep: Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967Reputation: 1967
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.
 
Old 04-28-2003, 09:56 AM   #7
mhearn
Guru
 
Registered: Nov 2002
Location: Durham, England
Distribution: Fedora Core 4
Posts: 1,565

Rep: Reputation: 47
Type this instead

source myscript

problem solved (for that shell). You probably want to stick it in your /etc/profile script though
 
Old 04-28-2003, 10:32 AM   #8
Mik
Senior Member
 
Registered: Dec 2001
Location: The Netherlands
Distribution: Ubuntu
Posts: 1,316

Rep: Reputation: 46
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.
 
Old 04-28-2003, 11:37 AM   #9
Crashed_Again
Senior Member
 
Registered: Dec 2002
Location: Atlantic City, NJ
Distribution: Ubuntu & Arch
Posts: 3,503

Rep: Reputation: 57
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.
 
Old 04-29-2003, 07:12 AM   #10
Donald1000
Member
 
Registered: Oct 2002
Location: Germany
Distribution: Debian, Non-Linux: Solaris, FreeBSD
Posts: 107

Original Poster
Rep: Reputation: 15
Thanks again! mhearn, i've tested it with the "source" command and it works. Great! Crashed_Again, i think your method works, too.
 
Old 03-12-2009, 09:03 PM   #11
Pada
LQ Newbie
 
Registered: Mar 2009
Location: Stellenbosch, South Africa
Posts: 2

Rep: Reputation: 0
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>"
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to export environment variable from a bash script dimaash Linux - Newbie 20 08-09-2011 08:12 AM
Asking a C program to call a bash script sceadu Programming 4 07-28-2005 09:52 PM
cannot export result from awk into a variable in a bash script Emmanuel_uk Linux - Newbie 4 03-07-2005 02:54 AM
set and export using bash script acummings Linux - General 10 01-03-2005 03:22 PM
BASH export command galalleni Slackware 4 09-08-2003 01:44 AM


All times are GMT -5. The time now is 04:39 AM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration