Variables

Preface a variable by a dollar sign ($) to reference its value. You can also optionally enclose it in braces ({ }). You can assign a value to a variable through an equals sign (=) with no whitespace on either side of it:

    $ TMP=temp.file

By default, variables are seen only within the shell itself; to pass variables to other programs invoked within the shell, see the export built-in command.

If followed by an index enclosed by brackets ([ ]), the variable is considered an array variable. For instance:

    $ DIR_LIST[0]=src
    $ DIR_LIST[1]=headers
    $ ls ${DIR_LIST[1]}

The contents of headers are listed. Many substitutions and commands in this chapter handle arrays by operating on each element separately.

Get Mac OS X Tiger in a Nutshell 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.