O'Reilly logo

Unix in a Nutshell, 4th Edition by Arnold Robbins

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 in 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.

$#

Same as ${#argv}.

${% var }

The number of characters in var.

${% n }

The number of characters in $argv[ n ].

$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 var is not set.

$?0

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

$$

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

$?

Same as $status.

$!

Process ID number of last background process started ...

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