Book HomeBook TitleSearch this book

B.4. Built-in Shell Variables

Here is a summary of all built-in shell variables:

Variable Chapter Meaning
# 4 Number of arguments given to current process.
@ 4

Command-line arguments to current process. Inside double quotes, expands to individual arguments.

* 4

Command-line arguments to current process. Inside double quotes, expands to a single argument.

- (hyphen)   Options given to shell on invocation.
? 5 Exit status of previous command.
$ 8 Process ID of shell process.
_ (underscore) 3

Inside $MAILPATH: the filename that triggered a "you have mail" message. On the command line: last argument to previous command. Inside a script: the full pathname used to find and run the script.

! 8 Process ID of last background command.
.sh.edchar 10

Characters entered when processing a KEYBD trap.

.sh.edcol 10

Position of the cursor in the most recent KEYBD trap.

.sh.edmode 10

Equal to ESC in vi-mode, empty otherwise.

.sh.edtext 10

Characters in the input buffer during a KEYBD trap.

.sh.match 4

Array variable with text that matched pattern in variable substitution. (Starting with ksh93l.)

.sh.name 9

Name of a variable executing a discipline function.

.sh.subscript 9

Subscript of an array variable executing a discipline function.

.sh.value 9

Value of the variable executing a discipline function.

.sh.version 4, 9

Version of ksh.

CDPATH 3 List of directories for cd command to search.
COLUMNS 3

Width of display in columns (for editing modes and select).

EDITOR 2

Used to set editing mode; also used by mail and other programs. Overriden by VISUAL, if that is set.

ENV 3

Name of file to run as environment file when shell is invoked.

FCEDIT 2 Obsolete default editor for hist command.
FIGNORE 1 Pattern for files to ignore during pattern expansion.
FPATH 4 Search path for autoloaded functions.
HISTCMD 2 Number of current command in command history.
HISTEDIT 2 Default editor for hist command.
HISTFILE 2 Name of command history file.
HISTSIZE 2 Number of lines kept in history file.
HOME 3 Home (login) directory.
IFS 7

Internal field separator: list of characters that act as word separators. Normally set to space, TAB, and newline.

LANG  

Default name of current locale; overridden by the other LC_* variables.

LC_ALL  

Name of current locale; overrides LANG and the other LC_* variables.

LC_COLLATE  

Name of current locale for character collation (sorting) purposes.

LC_CTYPE  

Name of current locale for character class determination during pattern matching; see Chapter 4.

LC_NUMERIC  

Name of current locale for number formatting (decimal point, thousands separator).

LINENO 9 Number of line in script or function that just ran.
LINES 3 Height of display in lines (for select command).
MAIL 3 Name of file to check for new mail.
MAILCHECK 3 How often (in seconds) to check for new mail.
MAILPATH 3

List of file names to check for new mail, if MAIL is not set.

OLDPWD 3 Previous working directory.
OPTARG 6 Argument to option being processed by getopts.
OPTIND 6 Number of first argument after options.
PATH 3 Search path for commands.
PPID 8 Process ID of parent process.
PS1 3 Primary command prompt string.
PS2 3 Prompt string for line continuations.
PS3 5 Prompt string for select command.
PS4 9 Prompt string for xtrace option.
PWD 3 Current working directory.
RANDOM 9

Random number between 0 and 32767 (215-1).

REPLY 5, 7

User's response to select command; result of read command if no variable names given.

SECONDS 3 Number of seconds since shell was invoked.
SHELL 3

Full pathname of shell programs should use to run commands.

TMOUT 5, 7, 10

If set to a positive integer, number of seconds between commands after which shell automatically terminates. Also applies to reading responses to select and read.

VISUAL 2 Used to set editing mode.



Library Navigation Links

Copyright © 2003 O'Reilly & Associates. All rights reserved.