Built-in Shell Variables

Table A-5 shows a complete list of environment variables available in bash 3.0. The letters in the Type column of the table have the following meanings: A = Array, L = colon-separated list, R = read-only, U = unsetting it causes it to lose its special meaning.

Note that the variables beginning BASH_ and beginning COMP, as well as the variables DIRSTACK, FUNCNAME, GLOBIGNORE, GROUPS, HISTIGNORE, HOSTNAME, HISTTIMEFORMAT, LANG, LC_ALL, LC_COLLATE, LC_MESSAGE, MACHTYPE, PIPESTATUS, SHELLOPTS, and TIMEFORMAT are not available in versions prior to 2.0. BASH_ENV replaces ENV found in earlier versions.

Table A-5. Built-in shell environment variables

Variable

Type

Description

*

R

A single string containing the positional parameters given to the current script or function, separated by the first character of $IFS (e.g., arg1 arg2 arg3).

@

R

Each of the positional parameters given to the current script or function, given as a list of double-quoted strings (e.g., "arg1" "arg2" "arg3").

#

R

The number of arguments given to the current script or function.

-

R

Options given to the shell on invocation.

?

R

Exit status of the previous command.

_

R

Last argument to the previous command.

$

R

Process ID of the shell process.

!

R

Process ID of the last background command.

0

R

Name of the shell or shell script.

BASH

 

The full pathname used to invoke this instance of bash.

BASH_ARGC

A

An array of values, which are the number of parameters in each frame of the current bash execution call stack. The number of parameters to the current subroutine (shell function or script executed with . or source) is at the top of the stack.

BASH_ARGV

A

All of the parameters in the current bash execution call stack. The final parameter of the last subroutine call is at the top of the stack; the first parameter of the initial call is at the bottom.

BASH_COMMAND

 

The command currently being executed or about to be executed, unless the shell is executing a command as the result of a trap, in which case it is the command executing at the time of the trap.

BASH_EXECUTION_STRING

 

The command argument to the -c invocation option.

BASH_ENV

 

The name of a file to run as the environment file when the shell is invoked.

BASH_LINENO

A

An array whose members are the line numbers in source files corresponding to each member of @var{FUNCNAME}. ${BASHLINENO[$i]} is the line number in the source file where ${FUNCNAME[$i + 1]} was called. The corresponding source filename is ${BASHSOURCE[$i + 1]}.

BASH_REMATCH

AR

An array whose members are assigned by the =~ binary operator to the [[ conditional command. The element with index 0 is the portion of the string matching the entire regular expression. The element with index n is the portion of the string matching the nth parenthesized subexpression.

BASH_SOURCE

A

An array containing the source filenames corresponding to the elements in the $FUNCNAME array variable.

BASH_SUBSHELL

 

Incremented by 1 each time a subshell or subshell environment is spawned. The initial value is 0. A subshell is a forked copy of the parent shell and shares it’s environment.

BASH_VERSION

 

The version number of this instance of bash.

BASH_VERSINFO

AR

Version information for this instance of bash. Each element of the array holds parts of the version number.

CDPATH

L

A list of directories for the cd command to search.

COMP_CWORD

 

An index into ${COMPWORDS} of the word containing the current cursor position. This variable is available only in shell functions invoked by the programmable completion facilities.

COMP_LINE

 

The current command line. This variable is available only in shell functions and external commands invoked by the programmable completion facilities.

COMP_POINT

 

The index of the current cursor position relative to the beginning of the current command. If the current cursor position is at the end of the current command, the value of this variable is equal to ${#COMPLINE}. This variable is available only in shell functions and external commands invoked by the programmable completion facilities.

COMP_WORDBREAKS

U

The set of characters that the Readline library treats as word separators when performing word completion. If COMP_WORDBREAKS is unset, it loses its special properties, even if it is subsequently reset.

COMP_WORDS

A

An array of the individual words in the current command line. This variable is available only in shell functions invoked by the programmable completion facilities.

COMPREPLY

A

The possible completions generated by a shell function invoked by the programmable completion facility.

DIRSTACK

ARU

The current contents of the directory stack.

EUID

R

The effective user ID of the current user.

FUNCNAME

ARU

An array containing the names of all shell functions currently in the execution call stack. The element with index 0 is the name of any currently-executing shell function. The bottom-most element is “main.” This variable exists only when a shell function is executing.

FCEDIT

 

The default editor for the fc command.

FIGNORE

L

A list of names to ignore when doing filename completion.

GLOBIGNORE

L

A list of patterns defining filenames to ignore during pathname expansion.

GROUPS

AR

An array containing a list of groups of which the current user is a member.

IFS

 

The Internal Field Separator: a list of characters that act as word separators. Normally set to space, tab, and newline.

HISTCMD

U

The history number of the current command.

HISTCONTROL

 

A list of patterns, separated by colons (:), which can have the following values: ignorespace: lines beginning with a space are not entered into the history list; ignoredups: lines matching the last history line are not entered; erasedups: all previous lines matching the current line to are removed from the history list before the line is saved; ignoreboth: enables both ignorespace and ignoredups.

HISTFILE

 

The name of the command history file.

HISTIGNORE

 

A list of patterns to decide what should be retained in the history list.

HISTSIZE

 

The number of lines kept in the command history.

HISTFILESIZE

 

The maximum number of lines kept in the history file.

HISTTIMEFORMAT

 

If set and not null, its value is used as a format string for strftime(3) to print the timestamp associated with each history entry displayed by the history built-in. If this variable is set, timestamps are written to the history file so they may be preserved across shell sessions.

HOME

 

The home (login) directory.

HOSTFILE

 

The file to be used for hostname completion.

HOSTNAME

 

The name of the current host.

HOSTTYPE

 

The type of machine bash is running on.

IGNOREEOF

 

The number of EOF characters received before exiting an interactive shell.

INPUTRC

 

The readline startup file.

LANG

 

Used to determine the locale category for any category not specifically selected with variable starting with LC_.

LC_ALL

 

Overrides the value of $LANG and any other LC_ variable specifying a locale category.

LC_COLLATE

 

Determines the collation order used when sorting the results of pathname expansion.

LC_CTYPE

 

Determines the interpretation of characters and the behavior of character classes within pathname expansion and pattern matching.

LC_MESSAGES

 

This variable determines the locale used to translate double-quoted strings preceded by a $.

LC_NUMERIC

 

Determines the locale category used for number formatting.

LINENO

U

The number of the line that just ran in a script or function.

MACHTYPE

 

A string describing the system on which bash is executing.

MAIL

 

The name of the file to check for new mail.

MAILCHECK

 

How often (in seconds) to check for new mail.

MAILPATH

L

A list of filenames to check for new mail, if $MAIL is not set.

OLDPWD

 

The previous working directory.

OPTARG

 

The value of the last option argument processed by getopts.

OPTERR

 

If set to 1, display error messages from getopts.

OPTIND

 

The number of the first argument after options.

OSTYPE

 

The operating system on which bash is executing.

PATH

L

The search path for commands.

PIPESTATUS

A

An array variable containing a list of exit status values from the processes in the most recently executed foreground pipeline.

POSIXLY_CORRECT

 

If in the environment when bash starts, the shell enters posix mode before reading the startup files, as if the --posix invocation option had been supplied. If it is set while the shell is running, bash enables posix mode, as if the command set -o posix had been executed.

PROMPT_COMMAND

 

The value is executed as a command before the primary prompt is issued.

PS1

 

The primary command prompt string.

PS2

 

The prompt string for line continuations.

PS3

 

The prompt string for the select command.

PS4

 

The prompt string for the xtrace option.

PPID

R

The process ID of the parent process.

PWD

 

The current working directory.

RANDOM

U

A random number between 0 and 32767 (215 - 1).

REPLY

 

The user’s response to the select command; result of the read command if no variable names are given.

SECONDS

U

The number of seconds since the shell was invoked.

SHELL

 

The full pathname of the shell.

SHELLOPTS

LR

A list of enabled shell options.

SHLVL

 

Incremented by 1 each time a new instance (not a subshell) of bash is invoked. This intended to be a count of how deeply your bash shells are nested.

TIMEFORMAT

 

Specifies the format for the output from using the time reserved word on a command pipeline.

TMOUT

 

If set to a positive integer, the number of seconds after which the shell automatically terminates if no input is received.

UID

R

The user ID of the current user.

auto_resume

 

Controls how job control works (values are exact, substring, or something other than those keywords).

histchars

 

Specifies what to use as the history control characters. Normally set to the string !^#.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.137.216.175