Latest LQ Deal: Latest LQ Deals
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 12-08-2005, 08:38 PM   #1
LQ Newbie
Registered: Dec 2005
Posts: 13

Rep: Reputation: 0
Post Need help setting environment variables via shell script


I am trying to use a shell script to set a bunch of environment variables. However, while the environment variables seem to be set during the life of the shell script, they does not persist in the environment once the script completes, even if I export the variables.

To test, I create a simple shell script (named

export TEST

Next, I run change the permissions:

chmod uog+x

Finally, I run the script:


After the script executes, I use the following command to see if the "TEST" variable is set:

set | grep -i "TEST"

Which returns nothing.

Can somebody tell me why TEST isn't set after the script is run, and more importantly, how to get it to stay set after the script completes? Typing "export TEST=test" at the command prompt works fine, and defining and exporting the variables in /etc/profile or .bash_profile works fine as well. However, I don't want to modify the bash profile; I have a bunch of variables that need to be initialized for a particular application, and I'd like to be able to do it with a shell script.

If it makes any difference I am running Fedora Core 3 and am logged in as root.

Thanks in advance,
Old 12-08-2005, 08:45 PM   #2
LQ Newbie
Registered: Dec 2005
Posts: 13

Original Poster
Rep: Reputation: 0


Sorry to waste your time. Once I posted my thread, I found other similar threads which answered my question. By using "." my problems are solved; being new to Linux I did not realize a new shell was being executed.

Old 12-08-2005, 08:58 PM   #3
Registered: Sep 2003
Location: Canada
Distribution: Fedora 30
Posts: 341

Rep: Reputation: 36
Hey Steve,
Ask away.
Do you know about .bash_profile. (If you are running bourne shell... or whatever the equivalent is in the others...)

Ok. a dot file is hidden .whatever,
so you have to do an ls -la from a terminal to see it.

Find out what loads at your particular login and edit it.
# .bash_profile

# Get the aliases and functions
if [ -f ~/.bashrc ]; then
. ~/.bashrc

# User specific environment and startup programs


export TEST



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
Setting environment variables from shell script theta Linux - General 5 09-02-2004 09:50 PM
Sub shell environment variables tnine9 Programming 1 06-08-2004 02:27 PM
Setting environment variables from a script... sylvain_gnu Linux - Newbie 5 04-20-2004 01:31 PM
setting environment variables durden2.0 Linux - Newbie 5 07-15-2003 02:57 PM
setting environment variables rezza Linux - Distributions 2 04-09-2003 09:21 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 11:50 PM.

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