Share your knowledge at the LQ Wiki.
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 09-29-2004, 07:36 AM   #1
Registered: Jul 2004
Posts: 34

Rep: Reputation: 15
bash shell env var script

Even though I did this before, I just do not remember what the h?ll I did. Again I am here as a 'newbie'

The script looks like so.

export MYVAR=/export/files

What must I do to be sure that MYVAR is available for me after the script completes?
Old 09-29-2004, 07:45 AM   #2
Senior Member
Registered: Nov 2002
Location: pikes peak
Distribution: Slackware, LFS
Posts: 2,577

Rep: Reputation: 48
add MYVAR to your local $PATH
Old 09-29-2004, 09:43 AM   #3
Registered: Jul 2004
Posts: 34

Original Poster
Rep: Reputation: 15
Well, that would make sense to me if I wanted MYVAR in the path. Simply, MYVAR is an environment variable that needs to stand on its own. For example, what if I wanted MYVAR=myVALUE.

Thanks in Advance.
Old 09-29-2004, 09:47 AM   #4
Registered: Mar 2004
Distribution: Debian Sarge, FC4
Posts: 100

Rep: Reputation: 15
colabus@xionous:~/mount$ export TEST="hello world"
colabus@xionous:~/mount$ echo $TEST
hello world
colabus@xionous:~/mount$ bash
colabus@xionous:~/mount$ echo $TEST
hello world
works fine for me?
Old 09-29-2004, 10:23 AM   #5
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.10, Centos 7.3
Posts: 17,524

Rep: Reputation: 2417Reputation: 2417Reputation: 2417Reputation: 2417Reputation: 2417Reputation: 2417Reputation: 2417Reputation: 2417Reputation: 2417Reputation: 2417Reputation: 2417
Shell vars only affect the current env values.
Using export means they will also take effect in any subsequent shells fired from that shell aka sub-shell.
You cannot pass values back up the chain to affect a higher level shell.
Use (write to) a file and read it back if you want to do that. eg
echo $MYVAR >>file.dat
to save, then
MYVAR=`cat file.dat` # NB: backquotes, not single quotes
to retrieve.


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 do you set a shell script var with a literal '*'? BrianK Programming 3 06-22-2004 02:11 PM
tcsh script: how to see if an env var is defined? BrianK Programming 1 06-07-2004 10:12 PM
bash script+ftp+ls->var g00ral Programming 1 05-05-2004 06:58 AM
bash/shell script mikis Programming 2 10-14-2003 11:39 AM
BASH shell script help ewarmour Programming 8 05-24-2002 07:57 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:11 AM.

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