Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
Notices |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
11-16-2009, 11:19 AM
|
#1
|
Member
Registered: Feb 2007
Posts: 386
Rep:
|
shell to set environment variable
I am trying to set environment variables via a shell script.
However, after the script exits, the env variable is still not set.
Is there a way to do so?
This is my aa.sh
export DPATH=/var/www/html/www.julycenter.com
export CPATH=/var/www/html/www.julycenter.com/css
|
|
|
11-16-2009, 11:24 AM
|
#2
|
Senior Member
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Rep: 
|
I don't think so, because the shell script is a child of the shell.
If you need for the values to persist, either 1) export them in the parent environment instead; or 2) write them to some sort of temporary file from the child environment (where they can later be read by the parent).
|
|
|
11-16-2009, 11:28 AM
|
#3
|
Senior Member
Registered: Dec 2003
Location: Trondheim, Norway
Distribution: Debian and Ubuntu
Posts: 1,466
|
Hi
Try this:
source aa.sh
Then the variables will be set.
|
|
|
11-16-2009, 11:31 AM
|
#4
|
LQ Veteran
Registered: Sep 2003
Posts: 10,532
|
Hi,
Do you have to use a script?
Running a script will not set these vars in the shell you started the script from.
Parsing a file with commands will set them in the shell you parsed in from.
. aa
aa being a file with just the 2 shown export commands in post #1.
Hope this helps.
|
|
|
11-16-2009, 11:31 AM
|
#5
|
Moderator
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
|
Quote:
Hi
Try this:
source aa.sh
Then the variables will be set.
|
or the short version
. script
|
|
|
11-16-2009, 11:35 AM
|
#6
|
Senior Member
Registered: Nov 2004
Location: Texas
Distribution: RHEL, Scientific Linux, Debian, Fedora
Posts: 3,935
Rep: 
|
Guttorm's idea does work if aa.sh does not have an exit.
Code:
$ cat foo.sh
#!/bin/sh
_myval='Hello'
. /home/mrbig/bar.sh
echo ${_myval}
exit 0
Code:
$ cat bar.sh
#!/bin/sh
_myval='Goodbye'
|
|
|
All times are GMT -5. The time now is 02:33 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|