Sunday, November 25, 2012

Linux Environment Variables by using export or not


Using export and not using export - environment variables

http://lowfatlinux.com/linux-environment-variables.html

code=$HOME/projects/src/spew
and then, regardless of what directory you are in, you can issue
cd $code
to pop over quickly to the directory containing the source code for that way-cool spew program you're developing. (The cd command means "change directory.")
A variable assignment like this will work just fine, but its scope (visibility) is limited to the current shell. If you launch a program or enter another shell, that child task will not know about your environment variables unless you export them first.
Unless you know for sure that an environment variable will have meaning only in the current shell, it's a good idea to always useexport when creating variables to ensure they will be global in scope--for example,
export PS1="\u \$ "
export code=$HOME/projects/src/spew
And be sure to add these commands to your .profile file so you won't have to retype them eac h time you log in.



http://en.wikibooks.org/wiki/Guide_to_Unix/Environment_Variables
http://en.wikipedia.org/wiki/Environment_variable


http://stackoverflow.com/questions/1158091/bash-defining-a-variable-with-or-without-export


export makes the variable available to sub-processes.
That is,
export name=value
means that the variable name is available to any process you run from that shell process. If you want a process to make use of this variable, use export, and run the process from that shell.
name=value
means the variable scope is restricted to the shell, and is not available to any other process. You would use this for (say) loop variables, temporary variables etc.


Specifically export makes the variable available to child processes via the environment. – Beano Jul 21 '09 at 13:35







No comments:

Post a Comment