z/OS UNIX System Services User's Guide
Previous topic | Next topic | Contents | Contact z/OS | Library | PDF


Using parameter and variable expansion

z/OS UNIX System Services User's Guide
SA23-2279-00

A $ followed by a number stands for a positional parameter passed to the script or function. A positional parameter is represented with either a single digit (except 0) or two or more digits in braces; for example, 7 and {15} are both valid representations of positional parameters. For example, if the command:
echo $1
appeared in a shell script, it would echo the first positional parameter.

Similarly, a $ followed by the name of a shell variable (such as $HOME) stands for the value of the variable.

These constructs are called parameter expansions. In this sense, the term parameter can mean either a positional parameter or a shell variable.

The tcsh shell also supports more complicated forms of parameter expansions, letting you obtain only part of a parameter value or a modified form of the value.

Modifier Description    
r Root of value    
e Extension of value    
h Head of value    
t Tail of value    

For example, to extract only part of a file name, you can add one of these modifiers as follows:

File name r e h t
/usr/bin/vi.txt /usr/bin/vi txt /usr/bin vi.txt
/u/bobby/mail /u/bobby/mail empty /u/bobby mail
storybook.pdf storybook pdf empty storybook.pdf
INSTALL INSTALL empty empty INSTALL

Go to the previous page Go to the next page




Copyright IBM Corporation 1990, 2014