O'Reilly logo

Mac OS X Panther in a Nutshell, 2nd Edition by Jason McIntosh, Chuck Toporek, Chris Stone

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Variables

This subsection describes the following:

  • Variable substitution

  • Variable modifiers

  • Predefined shell variables

  • Formatting for the prompt variable

  • Sample .tcshrc file

  • Environment variables

Variable Substitution

In the following substitutions, braces ({ }) are optional, except when needed to separate a variable name from following characters that would otherwise be considered part of the name.

Variable

Description

${ var }

The value of variable var.

${ var [ i ] }

Select word or words in position i of var. i can be a single number, a range m-n, a range - n (missing m implies 1), a range m - (missing n implies all remaining words), or * (select all words). i also can be a variable that expands to one of these values.

${# var }

The number of words in var.

${#argv}

The number of arguments.

$0

Name of the program.

${argv[ n ]}

Individual arguments on command line (positional parameters); 1 n 9.

${ n }

Same as ${argv[ n ]}.

${argv[*]}

All arguments on command line.

$*

Same as {$argv[*]}.

$argv[$#argv]

The last argument.

${? var }

Return 1 if var is set, 0 if not.

$$

Process number of current shell; useful as part of a filename for creating temporary files with unique names.

${? name }

Return 1 if name is set, 0 if not.

$?0

Return 1 if input filename is known, 0 if not.

Examples

Sort the third through last arguments, and save the output in a file whose name is unique to this process:

                     sort $argv[3-] > tmp.$$

Process .tcshrc commands ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required