Accessing Shell Variables

Shell variables are defined or changed with the set command. The unset command is used to delete a variable. See the Section called Environment Commands in the Chapter called Builtin Command Reference for more information on the set and unset commands.

To access shell variables from the command line or a shell script, use the character "$" followed by the variable name. The dollar sign character will expand the variable to its value. If you wish to use the dollar sign character in a string from the command line, remember to enclose it in single quotes or use the "\" escape character. If you use double quotes, the shell will try to expand the variable. To differentiate the variable name from characters that may immediately follow it, the variable name may be optionally surrounded with braces, "{" and "}".This provides a very powerful way of user interaction with shell scripts.