Environment variables

Variable assignments such as the ones we've done so far in this chapter are only visible to the current running shell. Their values don't implicitly affect a program called by the script  a forked process.

The easiest way to demonstrate this on the command line is to start another shell process after making an assignment. Consider this basic shell session, including an assignment to a variable named realname:

bash$ declare -p BASHPID
declare -ir BASHPID="7013"
bash$ realname='Bash User'
bash$ declare -p realname
declare -- realname='Bash User'

If we start a new bash process, we get a new process ID in BASHPID, and the realname variable does not show as a set:

bash$ bash bash$ declare -p BASHPID declare -ir BASHPID="7585" ...

Get Bash Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.