Another form of variable that you can use in a shell program is a named variable. You assign values to named variables yourself. The format for assigning a value to a named variable is:
named_variable=valueNotice that there are no spaces on either side of the equals (=) sign.
In the following example, var1 is a named variable, and myname is the value or character string assigned to that variable:
var1=mynameA ``$'' is used in front of a variable name in a shell program to reference the value of that variable. Using the example above, the reference $var1 tells the shell to substitute the value myname (assigned to var1), for any occurrence of the character string $var1.
The first character of a variable name must be a letter or an underscore. The rest of the name can consist of letters, underscores, and digits. Like shell program filenames, variable names should not be shell command names. Also, the shell reserves some variable names that you should not use for your variables. The following list provides brief descriptions of some of the most important of these reserved shell variable names.
You can see the value of these variables in your shell in two ways. First, you can type
echo $variable_nameThe system outputs the value of variable_name. Second, you can use the env(1) command to print out the value of all defined variables in the shell. To do this, type env on a line by itself; the system outputs a list of the variable names and values.