Skip to Main Content
Linux in a Nutshell, Fourth Edition
book

Linux in a Nutshell, Fourth Edition

by Ellen Siever, Stephen Figgins, Aaron Weber
June 2003
Beginner to intermediate content levelBeginner to intermediate
944 pages
43h 1m
English
O'Reilly Media, Inc.
Content preview from Linux in a Nutshell, Fourth Edition

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

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Linux in a Nutshell, 6th Edition

Linux in a Nutshell, 6th Edition

Ellen Siever, Stephen Figgins, Robert Love, Arnold Robbins
Linux in Action

Linux in Action

David Clinton
Hands-On System Programming with Linux

Hands-On System Programming with Linux

Kaiwan N. Billimoria, Tigran Aivazian
Embedded Linux for Developers

Embedded Linux for Developers

Alexandru Vaduva, Alex González, Chris Simmonds

Publisher Resources

ISBN: 0596004826