Variables

Variables are very good ways to simplify the administration of your shell scripts or for temporarily storing data for use by multiple commands in your script.

VARIABLE=value Examples:
PRINTER=printer-1232  
PATH=$PATH:/usr/sbin  

When referring to variables, you must always use the $ symbol as a prefix to the variable ($VARIABLE, $PRINTER, $PATH) but when assigning the variable, as shown above, the $ symbol is not allowed.

There are some special variables that are reserved (such as PATH) and you can read more about these in the man page for sh. Otherwise, you can create a variable that is named anything you choose.

Capturing output from a command into a variable can be very useful. You do this placing a command in single-forward quotation marks: `command`. Example:
DATE=`date`

Then you can act on this variable just as if it were any other text or data in your script: echo The date and time is currently: $DATE



Matt Disney 2005-09-14