您的位置:首页 > 运维架构 > Shell

Special Shell Variables

2015-09-22 15:47 856 查看
The Bourne shell has a number of special “automatic” variables that it maintains for informational purposes. These variables provide information such as the process ID of the shell, the exit status of the last command, and so on. This section provides a
list of these special variables. For additional variables supported by specific Bourne shell variants such as BASH and ZSH, see the
bash
and
zshparam
manual pages, respectively.

Table B-1 Special shell variables

Variable

Description

Process information

$$


Process ID of shell

$PPID


Process ID of shell’s parent process.

Quirk Warning:For subshells, the value of PPID is inherited from the parent shell. Thus, PPID is only the parent of the outermost shell process.

$?


Exit status of last command.

$_


Name of last command.

$!


Process ID of last process run in the background using ampersand (&) operator. This is commonly used in conjunction with the
wait
builtin.

$PATH


A colon-delimited list of locations where trusted executables are installed. Any executable in one of these locations can be executed without specifying a complete path.

Field and record parsing

$IFS


Input Field Separators (uses are explained in Variable Expansion and Field Separators)

User information

$HOME


The user’s home directory.

$UID


The user’s ID.

Security Warning:This value can be modified by the calling script, so it should not be used for authentication purposes.

$USER


The user’s (short) login name.

Security Warning:This value can be modified by the calling script, so it should not be used for authentication purposes.

Miscellaneous Variables

$#


Number of arguments passed to the shell. This variable is described further inHandling Flags and Arguments.

$@


Complete list of arguments passed to the shell, separated by spaces.. This variable is described further inHandling Flags and Arguments.

$*


Complete list of arguments passed to the shell, separated by the first character of the
IFS
(input field separators) variable. This variable is described further inHandling Flags and Arguments.

$-


A list of all shell flags currently enabled.

$PWD


The current working directory. Equivalent to executing the
pwd
command.

《文章出处》
https://developer.apple.com/library/mac/documentation/OpenSource/Conceptual/ShellScripting/SpecialShellVariables/SpecialShellVariables.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: