Export Variables

From Linux Shell Scripting Tutorial - A Beginner's handbook
Revision as of 22:27, 20 May 2010 by (talk)
Jump to navigation Jump to search

← QuotingHomeUnset →

The export builtin automatically exports to the environment of child processes. For example, Create the variable called vech, and give it a value "Bus":


Display the value of a variable with echo, enter:

echo "$vech"

Now, start a new shell instance, enter:


Now, display back the value of a variable vech with echo, enter:

echo $vech

You will get an empty line as the variable vech is not exported to new process. To make the variable known to child processes, use the export command. Try the following example at a console or terminal:

export backup="/nas10/mysql"
echo "Backup dir $backup"
echo "Backup dir $backup"

By default all user defined variables are local. They are not exported to new processes. Use export command to export variables and functions to child processes. If no variable names or function names are given, or if the -p option is given, a list of all names that are exported in this shell is printed. An argument of -n says to remove the export property from subsequent NAMEs.

export -p

Please note that system environment variables are passed to new processes. ← QuotingHomeUnset →