Skip to Content
Linux in a Nutshell, 6th Edition
book

Linux in a Nutshell, 6th Edition

by Ellen Siever, Stephen Figgins, Robert Love, Arnold Robbins
September 2009
Beginner
942 pages
85h 34m
English
O'Reilly Media, Inc.
Content preview from Linux in a Nutshell, 6th Edition

Built-in Shell Variables

Built-in variables are automatically set by the shell and are typically used inside shell scripts. Built-in variables can make use of the variable substitution patterns shown previously. Note that the $ is not actually part of the variable name, although the variable is always referenced this way.

Variable

Description

$#

Number of command-line arguments.

$-

Options currently in effect (arguments supplied on command line or to set).

$?

Exit value of last executed command.

$$

Process number of current process.

$!

Process number of last background command.

$0

First word; that is, command name. This will have the full pathname if it was found via a PATH search.

$ n

Individual arguments on command line (positional parameters). If n is greater than 9, it must be specified as ${ n}.

$*, $@

All arguments on command line ($1 $2 ...).

“$*”

All arguments on command line as one string (“$1 $2 ..."). The values are separated by the first character in the IFS special variable.

“$@”

All arguments on command line, individually quoted (“$1” “$2” ...).

$_

Temporary variable; initialized to pathname of script or program being executed. Later, stores the last argument of previous command. Also stores name of matching MAIL file during mail checks.

HISTCMD

The history number of the current command.

LINENO

Current line number within the script or function.

OLDPWD

Previous working directory (set by cd).

OPTARG

Name of last option processed by getopts.

OPTIND

Numerical index of OPTARG.

PPID

Process number of this ...

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

Unix in a Nutshell, 4th Edition

Unix in a Nutshell, 4th Edition

Arnold Robbins
Linux Under the Hood

Linux Under the Hood

Sander van Vugt
Linux Kernel in a Nutshell

Linux Kernel in a Nutshell

Greg Kroah-Hartman

Publisher Resources

ISBN: 9780596806088Errata Page