LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
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
  Search this Thread
Old 09-29-2004, 07:36 AM   #1
ejbest
Member
 
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.

-------------------------------
#!/bin/bash
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
320mb
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
ejbest
Member
 
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
colabus
Member
 
Registered: Mar 2004
Distribution: Debian Sarge, FC4
Posts: 100

Rep: Reputation: 15
Code:
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
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,358

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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.
 
  


Reply



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

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:31 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration