When setting up a variable in
.bashrc should I use this:
Or would this be enough:
What is exactly the difference (if there is one)?
only sets the variable for the duration of the script (.bashrc in this case). Child processes (if any) of the script won't have VAR defined, and once the script exits VAR is gone.
explicitly adds VAR to the list of variables that are passed to child processes. Want to try it? Open a shell, do
The new shell gets the default prompt. If instead you do something like
the new shell gets the prompt you just set.
Update: as Ian Kelling notes below variables set in .bashrc persist in the shell that sourced .bashrc. More generally whenever the shell sources a script (using the
Both seem to work just fine, but using export will ensure the variable is available to subshells and other programs. To test this out try this.
Add these two lines to your .bashrc file
Then open a new shell.