内容来自:abs-guide



$BASH
The path to the Bash binary itself
bash$ echo $BASH
/bin/bash
$BASH_ENV
An environmental variable pointing to a Bash startup file to be read when a script is invoked
$BASH_SUBSHELL
A variable indicating the subshell level. This is a new addition to Bash, version 3.
See Example 21-1 for usage.
$BASHPID
Process ID of the current
$BASH_VERSINFO[n]
A 6-element array containing version information about the installed release of Bash. This is similar
to $BASH_VERSION, below, but a bit more detailed.
for n in 0 1 2 3 4 5
do
echo "BASH_VERSINFO[$n] = ${BASH_VERSINFO[$n]}"
done
# BASH_VERSINFO[0] = 3 # Major version no.
# BASH_VERSINFO[1] = 00 # Minor version no.
# BASH_VERSINFO[2] = 14 # Patch level.
# BASH_VERSINFO[3] = 1 # Build version.
# BASH_VERSINFO[4] = release # Release status.
# BASH_VERSINFO[5] = i386-redhat-linux-gnu # Architecture
$BASH_VERSION
The version of Bash installed on the system
$CDPATH
A colon-separated list of search paths available to the cd command, similar in function to the $PATH
variable for binaries. The $CDPATH variable may be set in the local ~/.bashrc file.
$DIRSTACK
The top value in the directory stack [41] (affected by pushd and popd)
This builtin variable corresponds to the dirs command, however dirs shows the entire contents of the
directory stack.
$EDITOR
The default editor invoked by a script, usually vi or emacs .
$EUID
"effective" user ID number
Identification number of whatever identity the current user has assumed, perhaps by means of su.
The $EUID is not necessarily the same as the $UID.
$FUNCNAME
Name of the current function
xyz23 ()
{
echo "$FUNCNAME now executing." # xyz23 now executing.
}
xyz23
echo "FUNCNAME = $FUNCNAME" # FUNCNAME =
# Null value outside a function.


$GLOBIGNORE
A list of filename patterns to be excluded from matching in globbing.
$GROUPS
Groups current user belongs to
This is a listing (array) of the group id numbers for current user, as recorded in /etc/passwd and
/etc/group.
root# echo $GROUPS
0
root# echo ${GROUPS[1]}
1
root# echo ${GROUPS[5]}
6
$HOME
Home directory of the user, usually /home/username (see Example 10-7)
$HOSTNAME
The hostname command assigns the system host name at bootup in an init script. However, the
gethostname() function sets the Bash internal variable $HOSTNAME. See also Example 10-7.
$HOSTTYPE
host type
Like $MACHTYPE, identifies the system hardware.
$IFS
internal field separator
This variable determines how Bash recognizes fields, or word boundaries, when it interprets character
strings.
$IFS defaults to whitespace (space, tab, and newline), but may be changed, for example, to parse a
comma-separated data file. Note that $* uses the first character held in $IFS.


bash$ echo "$IFS"
(With $IFS set to default, a blank line displays.)
bash$ echo "$IFS" | cat -vte
^I$
$
(Show whitespace: here a single space, ^I [horizontal tab],
and newline, and display "$" at end-of-line.)
bash$ bash -c 'set w x y z; IFS=":-;"; echo "$*"'
w:x:y:z
(Read commands from string and assign any arguments to pos params.)
$IGNOREEOF
Ignore EOF: how many end-of-files (control-D) the shell will ignore before logging out.
$LC_COLLATE
Often set in the .bashrc or /etc/profile files,
this variable controls collation order in filename
expansion and pattern matching. If mishandled, LC_COLLATE can cause unexpected results in
filename globbing.
As of version 2.05 of Bash, filename globbing no longer distinguishes between
lowercase and uppercase letters in a character range between brackets. For example, ls
[A-M]* would match both File1.txt and file1.txt .
To revert to the customary
behavior of bracket matching, set LC_COLLATE to C by
an export LC_COLLATE=C in /etc/profile and/or ~/.bashrc .
$LC_CTYPE
This internal variable controls character interpretation in globbing and pattern matching.
$LINENO
This variable is the line number of the shell script in which this variable appears. It has significance
only within the script in which it appears, and is chiefly useful for debugging purposes.
# *** BEGIN DEBUG BLOCK ***
last_cmd_arg=$_ # Save it.
echo "At line number $LINENO, variable \"v1\" = $v1"
echo "Last command argument processed = $last_cmd_arg"
# *** END DEBUG BLOCK ***
$MACHTYPE
machine type
Identifies the system hardware.
$OLDPWD
Old working directory ("OLD-Print-Working-Directory", previous directory you were in).
$OSTYPE
operating system type
$PATH
Path to binaries, usually /usr/bin/, /usr/X11R6/bin/, /usr/local/bin, etc.
PATH=${PATH}:/opt/bin appends the /opt/bin directory to the current path. In a script,
it
may be expedient to temporarily add a directory to the path in this way. When the script exits, this
restores the original $PATH (a child process, such as a script, may not change the environment of the
parent process, the shell).
$PIPESTATUS
Array variable holding exit status(es) of last executed foreground pipe.
bash$

echo $PIPESTATUS

0
bash$ls -al | bogus_command
bash: bogus_command: command not found
bash$

echo ${PIPESTATUS[1]}

127
bash$ls -al | bogus_command
bash: bogus_command: command not found
bash$

echo $?

127
The members of the $PIPESTATUS array hold the exit status of each respective command executed
in a pipe. $PIPESTATUS[0] holds the exit status of the first command in the pipe,
$PIPESTATUS[1] the exit status of the second command, and so on
$PPID
The $PPID of a process is the process ID (pid) of its parent process. [42]
Compare this with the pidof command.
$PROMPT_COMMAND
A variable holding a command to be executed just before the primary prompt, $PS1 is to be
displayed.
$PS1
This is the main prompt, seen at the command-line.
$PS2
The secondary prompt, seen when additional input is expected. It displays as ">".
$PS3
The tertiary prompt, displayed in a select loop (see Example 11-29).
$PS4
The quartenary prompt, shown at the beginning of each line of output when invoking a script with the
-x option. It displays as "+".
$PWD
Working directory (directory you are in at the time)
$REPLY
The default value when a variable is not supplied to read. Also applicable to select menus, but only
supplies the item number of the variable chosen, not the value of the variable itself.
$SECONDS
The number of seconds the script has been running.
$SHELLOPTS
The list of enabled shell options, a readonly variable.
$SHLVL
Shell level, how deeply Bash is nested. [43] If, at the command-line, $SHLVL is 1, then in a script it
will increment to 2.
$TMOUT
If the $TMOUT environmental variable is set to a non-zero value time, then the shell prompt will
time out after $time seconds. This will cause a logout.
$UID
User ID number
Current user's user identification number, as recorded in /etc/passwd
This is the current user's real id, even if she has temporarily assumed another identity through su.
$UID is a readonly variable, not subject to change from the command line or within a script, and is
the counterpart to the id builtin.
$0, $1, $2, etc.
Positional parameters, passed from command line to script, passed to a function, or set to a variable
(see Example 4-5 and Example 15-16)
$#
Number of command-line arguments [44] or positional parameters (see Example 36-2)
$*
All of the positional parameters, seen as a single word
"$*" must be quoted.
$@
Same as $*, but each parameter is a quoted string, that is, the parameters are passed on intact, without
interpretation or expansion. This means, among other things, that each parameter in the argument list
is seen as a separate word.
The $@ and $* parameters differ only when between double quotes.
#!/bin/bash
# If $IFS set, but empty,
#+ then "$*" and "$@" do not echo positional params as expected.
mecho () # Echo positional parameters.
{
echo "$1,$2,$3";
}
IFS="" # Set, but empty.
set a b c # Positional parameters.
mecho "$*" # abc,,
# ^^
mecho $* # a,b,c
mecho $@ # a,b,c
mecho "$@" # a,b,c
$-
Flags passed to script (using set).
$!
PID (process ID) of last job run in background
$_
Special variable set to final argument of previous command executed
$?
Exit status of a command, function, or the script itself (see Example 24-7)
$$
Process ID ( PID) of the script itself



shell Builtin variables(shell内建变量)的更多相关文章

  1. learning shell built-in variables (1)

    Shell built-in variables [Purpose]        Learning shell built-in variables, example $0,$1,$2,$3,$#, ...

  2. (转)8个有力的Awk内建变量

    8个有力的Awk内建变量 翻译原文:8 Powerful Awk Built-in Variableshttp://www.thegeekstuff.com/这个博客真是不错. 这篇文章是Awk Tu ...

  3. Paip.最佳实践-- Buildin variale 内建变量 ,魔术变量,预定义变量,系统常量,系统变量 1

    Paip.最佳实践-- Buildin variale 内建变量 ,魔术变量,预定义变量,系统常量,系统变量 1.1.1       C++内建变量(__LINE__).... 1.1.2       ...

  4. OpenGL ES着色器语言之语句和结构体(官方文档第六章)内建变量(官方文档第七、八章)

    OpenGL ES着色器语言之语句和结构体(官方文档第六章) OpenGL ES着色器语言的程序块基本构成如下: 语句和声明 函数定义 选择(if-else) 迭代(for, while, do-wh ...

  5. Go内建变量类型

    package main import ( "math/cmplx" "fmt" "math" ) //内建变量类型: // bool , ...

  6. Linux - Bash shell的功能;内建命令type

    命令编修能力 (history): bash 的功能里头,相当棒的一个就是『他能记忆使用过的命令!』 这功能真的相当的棒!因为我只要在命令列按『上下键』就可以找到前/后一个输入的命令!而在很多 dis ...

  7. Linux编程 10 (shell外部命令与内建命令,alias ,type命令)

    一.  内部命令 Linux命令有内部命令(内建命令)和外部命令之分,内部命令和外部命令功能基本相同,但也有些细微差别.内部命令不需要使用子进程来执行,它们已经和shell编译成一体,作为shell工 ...

  8. Linux 8个有力的Awk内建变量

    Awk 有几个非常强力的内置变量.通常来说,分为两种类型的内置变量: 第一种是定义的变量可以改变, 比如字段分隔(FS)与记录分隔(RS) 第二种是可以用来数据处理或者数据总结,比如记录数(NR)与字 ...

  9. shell 学习笔记4-shell内置变量命令

    一.shell 的一些内置命令 常用的一内部命令有:echo.eval.exec.export.read.shift 1.echo命令-在屏幕中输出信息 1)说明 格式:echo args #< ...

随机推荐

  1. DOM基本概念和操作

    1.基本概念 DOM是文档对象模型(TEXT),对象是指文档中的每一个元素. 2.Window对象操作 打开方式: _blank  在新窗口还是自身窗口. Window.open 也有返回值,返回值为 ...

  2. 26数据查询的各种小玩法-select 下(必学)-天轰穿sqlserver视频教程

    大纲:简单查询-选择数据列,使用字符串,改变列标题,使用数据运算,使用ALL语DISTINCT关键字,使用TOP关键字,排序 优酷超清地址,为了冲优酷的访问量,所以这里只放优酷的地址了,其实其他网站还 ...

  3. 部署rfc5766-turn-server--谷歌推荐的开源穿透服务器 [复制链接]

    谷歌推荐的开源穿透服务器,包含trun和stun服务,主页:https://code.google.com/p/rfc5766-turn-server/(个人觉得可以利用这个来进一步搭建VPN,有兴趣 ...

  4. Java 定时任务

    control 类 Date nowDate = new Date(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH: ...

  5. NEWS - InstallShield 2013 SP1发布

    2013的这个国庆假期期间,InstallShield厂商Flexerasoftware(中文名:福莱睿)发布了最新版本InstallShield 2013的SP1,由于这个升级包带来一些新的技术支持 ...

  6. Python:将utf-8格式的文件转换成gbk格式的文件

    需求:将utf-8格式的文件转换成gbk格式的文件 实现代码如下: def ReadFile(filePath,encoding="utf-8"): with codecs.ope ...

  7. Android中解决图像解码导致的OOM问题

    Android中解决图像解码导致的OOM问题 原文链接:http://blog.csdn.net/zjl5211314/article/details/7042017

  8. VB中WinSock控件的属性、方法、事件及应用

    一.WinSock简介       Socket(套接字)最初是由加利福尼亚大学Berkeley(伯克利)分校为UNIX操作系统开发的网络通信接口,随着UNIX的广泛使用,Socket成为当前最流行的 ...

  9. nodejs+express+jade安装备忘

    安装步骤 1.安装nodejs,比如安装在E:\nodejs. 确保有两个环境变量 用户环境变量:C:\Users\Administrator\AppData\Roaming\npm 系统环境变量:e ...

  10. http协议读书笔记2-连接管理

    一.http是如何使用tcp连接的? http连接本质就是tcp连接和一些使用连接的规则.所有的http通讯都是由tcp/ip来承载的.tcp/ip是全球计算机及网络设备都在使用的一种常用的分组交换的 ...