内容来自: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. paip.中文 分词 -- 同义词大全整理

    paip.中文 分词 -- 同义词大全整理 同义词的处理方法: 作者Attilax  艾龙,  EMAIL:1466519819@qq.com  来源:attilax的专栏 地址:http://blo ...

  2. IOS开发之控件篇UITabBarControllor第一章 - 介绍

    UITabBarControllor的基本样子 官方有个图介绍这个TabBar的结构,我们先来看看这个结构图 --------------------------------------------- ...

  3. 大家一起写mvc(三)_结束

    上一篇介绍到要写mvc的所用的核心技术,这一篇我们就开始真正的开始写mvc,其实就是把昨天写过的代码进行一些组装就可以了. 我们用eclipse新建一个web项目.然后web.xml如下 <?x ...

  4. HTML 邮件链接,超链接发邮件

    在网页中可以设置如“联系我们”.“问题反馈”等所谓的邮箱链接,类似网页超链接,只是可以直接打开默认邮箱程序. 使用<a href="mailto:youEMail@xxx.yyy&qu ...

  5. NPOI 添加行

    IRow sourceRow = sheet1.GetRow(); ; i < dt.Rows.Count-; i++) { IRow row = sheet1.CreateRow( + i); ...

  6. 构造函数模式自己定义js对象

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  7. arcgis手动启动服务提示端口4000被使用

    具体解决办法 参考 http://hi.baidu.com/xjx19860908/item/6b46376d92044694c4d249f6该博文. 手动启动,提示4000端口被占用,去查找4000 ...

  8. 一个3D的多人在线游戏, 服务端 + 客户端 【转】

    最近学院组织了一个实训,要求是利用Socket通信和D3D的知识, 写一个多人在线的游戏, 服务端是在linux下, 客户是在Windows下: 写这个的目的是想让大家给我找错, 欢迎大家的意见.我的 ...

  9. 用etckeeper来解救运维工程师

    对于运维工程师来讲,etc环境是一个痛点,各种配置,各种修改,某些软件的配置关联因素过多的话,那就更加痛苦了,改完发现不对再想改回去都千难万难, 现在有一个好的解决方案,那就是用etckeeper,绝 ...

  10. 删除数据报ORA-00600: internal error code, arguments: [ktbesc_plugged]

    Oracle在删除数据是以下错误: ORA-00600: internal error code, arguments: [ktbesc_plugged], [], [], [], [], [], [ ...