LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   bash shell env var script (https://www.linuxquestions.org/questions/linux-newbie-8/bash-shell-env-var-script-236602/)

ejbest 09-29-2004 07:36 AM

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?

320mb 09-29-2004 07:45 AM

add MYVAR to your local $PATH

ejbest 09-29-2004 09:43 AM

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.

colabus 09-29-2004 09:47 AM

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?

chrism01 09-29-2004 10:23 AM

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.


All times are GMT -5. The time now is 05:43 AM.