LinuxQuestions.org
Help answer threads with 0 replies.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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

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

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


Hi,

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 test.sh):

#!/bin/sh
TEST=test
export TEST

Next, I run change the permissions:

chmod uog+x test.sh

Finally, I run the script:

./test.sh

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,
Steve
 
Old 12-08-2005, 07:45 PM   #2
srosburg
LQ Newbie
 
Registered: Dec 2005
Posts: 13

Original Poster
Rep: Reputation: 0
Nevermind...

All,

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

Regards,
Steve
 
Old 12-08-2005, 07:58 PM   #3
alar
Member
 
Registered: Sep 2003
Location: Canada
Distribution: CentOS 5.5, Ubuntu 10.04, Linux Mint 11 gnome 64 bit
Posts: 336

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
fi

# User specific environment and startup programs

PATH=$PATH:$HOME/bin

TEST=test
export TEST
---------------

 
  


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
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Setting environment variables from shell script theta Linux - General 5 09-02-2004 08:50 PM
Sub shell environment variables tnine9 Programming 1 06-08-2004 01:27 PM
Setting environment variables from a script... sylvain_gnu Linux - Newbie 5 04-20-2004 12:31 PM
setting environment variables durden2.0 Linux - Newbie 5 07-15-2003 01:57 PM
setting environment variables rezza Linux - Distributions 2 04-09-2003 08:21 AM


All times are GMT -5. The time now is 07:39 PM.

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