Exporting a variable value
Setting a variable using the Syntax above will cause the variable to only be available to the current shell instance. Usually, you want the variable to be propagated to any commands that you execute from the shell. To do this, you need to "export" the variable.
student@debian:~$ VAR=value
student@debian:~$ export VAR
You can also combine this into a single command:
student@debian:~$ export VAR=value
Let's have a look at an example of re-setting a variable and then exporting the value:
For this example we are going to use our login prompt variable called PS1, see the "set" command above.
student@debian:~$ PS1="newprompt $ "
newprompt $ _
Note
Enclose this in quotation marks to protect the spaces.
Now open a new shell and check for yourself that the prompt returns to the original prompt:
newprompt $ bash
student@debian:~$
Exit back to the original shell and export your variable PS1.
newprompt $ bash
student@debian:~$
student@debian:~$ exit
newprompt $ export PS1
newprompt $ bash
newprompt $
Now your new prompt has been exported to all subsequent shells.
Please note however that once you logout of this session your prompt will return to the default in your next log in. If you want to change this permanently change PS1 and export the value into one of your startup files. ($HOME/.bashrc or $HOME/.bash_profile)