内容来自: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. yafphp框架

    学习资料 Yaf(Yet Another Framework)用户手册http://www.laruence.com/manual/index.html laruence/yafhttps://git ...

  2. Atitit. 提升开发效率与质量DSL ( 3) ----实现DSL的方式总结

    Atitit. 提升开发效率与质量DSL ( 3) ----实现DSL的方式总结 1. 管道抽象 1 2. 层次结构抽象(json,xml etc) 1 3. 异步抽象promise 1 4. Ide ...

  3. Leetcode-237 Delete Node in a Linked List

    #237.    Delete Node in a Linked List Write a function to delete a node (except the tail) in a singl ...

  4. javascript效果:手风琴、轮播图、图片滑动

    最近都没有更,就来几个效果充实一下. 都没有进行美化这步. 手风琴: 纯css: <!DOCTYPE html> <html lang="en"> < ...

  5. Qt for Android 打包 SQLite 数据库

    Qt for Android 调用 SQLite 数据库时, 怎样将已经存在的数据库附加到 APK 中? 直接在你项目里面的Android源码的根目录下新建一个文件夹assets, 数据库就可以放里面 ...

  6. 如何管理和记录 SSIS 各个 Task 的开始执行时间和结束时间以及 Task 中添加|删除|修改的记录数

    开篇语 在这篇日志中 如何在 ETL 项目中统一管理上百个 SSIS 包的日志和包配置框架 我介绍到了包级别的日志管理框架,那么这个主要是针对包这一个层级的 Log 信息,包括包开始执行和结束时间,以 ...

  7. iOS Vuforia:TextReco 增加自己的单词库

          Vuforia的文字识别引擎提供了很好的文字识别功能.引擎依赖于UTF-8字符编码,现支持的字符有A-Z a-z,换行符.空格.单引号.短斜杠.Note:不支持中文及数字.能识别的字体是: ...

  8. [转] Python 代码性能优化技巧

    选择了脚本语言就要忍受其速度,这句话在某种程度上说明了 python 作为脚本的一个不足之处,那就是执行效率和性能不够理想,特别是在 performance 较差的机器上,因此有必要进行一定的代码优化 ...

  9. C#人爱学不学9[C#5.0异步实例+WPF自己的MVVM Async应用 1/12]

    文章摘要: 1. 通过简单DEMO.让读者理解Task和Task<T>    学习过程中,掌握async和await 2. 理解同步和异步的执行 3. Task.Factory.Start ...

  10. web项目中加入struts2、spring的支持,并整合两者

    Web项目中加入struts2 的支持 在lib下加入strut2的jar包 2. 在web.xml中添加配置 <filter> <filter-name>struts2< ...