When we look at what our shells do, there is, for example:
- waiting for user input
- interpreting user input
- acting on user input
- communicating with other programs/processes
And, of course, there is
- printing data to the screen
... to the terminal, actually. Anyway, the shells take action, so that the user can look at data.
Expanding a variable is what a shell does when it interprets the user's input. The shell recognises the user made a reference to a variable and continues to interpret the user's input as if the user input contained the content of the variable, rather than the reference.
For instance, let there be a variable
FOO which stores the value
bar. The user types the statement
echo $FOO. The shell starts to interpret this statement, recognises
$FOO as a reference to the variable named
FOO and proceeds to interpreting the statement as if the user had typed the statement
Printing a variable is projecting its content in a manner that lets the user perceive, i.e. read, it. It is executing the actual task of processing the value stored in the variable so that it is transported to the user. In the example of
echo $FOO, the variable
FOOis first expanded and then, as a result of the expansion, the
echo routine prints the content of
FOO to the screen.
In a sense, printing a value is the opposite of expanding a variable. A variable is expanded when the shell is reading in data, to determine what to do. When a variable is printed, the shell is handing out data, to the user.