bash

http://www.gnu.org/software/bash/manual/bash.html#Introduction
 
3.1.2.1 Escape Character

A non-quoted backslash ‘\’ is the Bash escape character. It preserves the literal value of the next character that follows, with the exception of newline. If a \newline pair appears, and the backslash itself is not quoted, the \newline is treated as a line continuation (that is, it is removed from the input stream and effectively ignored).

非引用反斜杠"\"是bash转义字符。它保留了跟随它的下一个字符的字面意义,除了换行符。如果\newline一起出现,并且反斜杠本身没有被引用,那么\newline被当作行连续对待

3.1.2.2 Single Quotes

Enclosing characters in single quotes (‘'’) preserves the literal value of each character within the quotes. A single quote may not occur between single quotes, even when preceded by a backslash.

单引号包围的字符保留了在引号里面每个字符的字面意义。在单引号之间不允许出现单引号,即使这个单引号之前有反斜杠。也就是说单引号之间的一个或多个单引号都将被忽略。

[root@250-shiyan ~]# echo '$p\'wd''
$p\wd
[root@250-shiyan ~]# echo '$p'wd''
$pwd

3.1.2.3 Double Quotes

Enclosing characters in double quotes (‘"’) preserves the literal value of all characters within the quotes, with the exception of ‘$’, ‘`’, ‘\’, and, when history expansion is enabled, ‘!’. The characters ‘$’ and ‘`’ retain their special meaning within double quotes (see Shell Expansions). The backslash retains its special meaning only when followed by one of the following characters: ‘$’, ‘`’, ‘"’, ‘\’, or newline. Within double quotes, backslashes that are followed by one of these characters are removed. Backslashes preceding characters without a special meaning are left unmodified. A double quote may be quoted within double quotes by preceding it with a backslash. If enabled, history expansion will be performed unless an ‘!’ appearing in double quotes is escaped using a backslash. The backslash preceding the ‘!’ is not removed.

The special parameters ‘*’ and ‘@’ have special meaning when in double quotes (see Shell Parameter Expansion).

双引号包围的字符保留了在引号里面每个字符的字面意义,但$,`,\,和!(当历史扩展启用时)。在双引号中的字符$和`保留了它们的特殊含义。反斜杠保留了它的特殊含义仅当后面跟随下列字符之一时:$,`,",\,or newline。

 

Bash is the GNU Project's shell. Bash is the Bourne Again SHell. Bash is an sh-compatible shell that incorporates useful features from the Korn shell (ksh) and C shell (csh). It is intended to conform to the IEEE POSIX P1003.2/ISO 9945.2 Shell and Tools standard. It offers functional improvements over sh for both programming and interactive use. In addition, most sh scripts can be run by Bash without modification.

The improvements offered by Bash include:

  • Command line editing
  • Unlimited size command history
  • Job Control
  • Shell Functions and Aliases
  • Indexed arrays of unlimited size
  • Integer arithmetic in any base from two to sixty-four

bash是一个gnu 项目的shell。bash是Bourne Again SHell的缩写。它是一个sh兼容的shell,并且合并(吸收或者嵌入)来自ksh和csh的有用特性。它意在符合两个标准。它在编程与交互使用方面提供的功能改进超过sh。此外多数的sh脚本可以被bash不加修改的运行。

由bash提供的改进包括:

命令行编辑
不限大小的命令历史
任务控制
shell函数与别名
不限大小的索引数组
从二进制的整数运算到64进制的整数运算都可以,base64就是64进制的范例
 
3.2.1 Simple Commands
A simple command is the kind of command encountered most often. It’s just a sequence of words separated by blanks, terminated by one of the shell’s control operators (see Chapter 2 [Definitions], page 3). The first word generally specifies a command to be executed, with the rest of the words being that command’s arguments.
简单命令是遇到最频繁的一类命令。它只是由空白符分隔,由shell控制操作符其中之一终止的单词序列。第一个单词通常指定一个被执行的命令,单词的其余部分成为命令的参数。
The return status (see Section 3.7.5 [Exit Status], page 38) of a simple command is its exit status as provided by the posix 1003.1 waitpid function, or 128+n if the command was terminated by signal n.
一个简单命令的返回状态是由posix 1003.1标准的waitpid函数提供的退出状态,或者是128+n如果命令被信号n终止。
4 Shell Builtin Commands
Builtin commands are contained within the shell itself. When the name of a builtin command is used as the first word of a simple command (see Section 3.2.1 [Simple Commands],page 8), the shell executes the command directly, without invoking another program. Builtin commands are necessary to implement functionality impossible or inconvenient to obtain with separate utilities.
内置命令被包含进shell本身。当一个内置命令的名字被用作一个简单命令的第一个单词时,shell不用调用另一个程序,并直接执行命令。内置命令对实现功能来说是必须的。
This section briefly describes the builtins which Bash inherits from the Bourne Shell, as well as the builtin commands which are unique to or have been extended in Bash.
这部分简短地描述了继承自bourne shell的bash的内置命令,还有一些独特的或已被bash扩展的内置命令。
Several builtin commands are described in other chapters: builtin commands which provide the Bash interface to the job control facilities (see Section 7.2 [Job Control Builtins],page 98), the directory stack (see Section 6.8.1 [Directory Stack Builtins], page 90), the command history (see Section 9.2 [Bash History Builtins], page 133), and the programmable completion facilities (see Section 8.7 [Programmable Completion Builtins], page 126).
一些内置命令在其它章节中描述:提供bash接口给job控制事务的内置命令参见,提供目录栈的内置命令参见,...和可编程的完全事务参见。
Many of the builtins have been extended by posix or Bash.
多数内置命令已被posix或者bash扩展。
Unless otherwise noted, each builtin command documented as accepting options preceded by ‘-’ accepts ‘--’ to signify the end of the options. The :, true, false, and test builtins do not accept options and do not treat ‘--’ specially. The exit, logout, break,continue, let, and shift builtins accept and process arguments beginning with ‘-’ without requiring ‘--’. Other builtins that accept arguments but are not specified as accepting options interpret arguments beginning with ‘-’ as invalid options and require ‘--’ to prevent this interpretation.
除非特别说明,每一个内置命令被记载为通过-接受选项,在选项结束之前,由--表示  比较乱
:,true,false,和test内置命令不接受选项,也不特别对待--。
exit,logout,break,continue,let和shift内置命令接受并处理以-开始,不需要--的参数。
其它内置命令接受参数,参数没有指定接受选项说明,以-开头的参数是无效的选项  比较乱
 
4.4 Special Builtins
For historical reasons, the posix standard has classified several builtin commands as special. When Bash is executing in posix mode, the special builtins differ from other builtin commands in three respects:
由于历史原因,posix 标准已经分类了一些内置命令作为special。
当Bash在posix模式下执行时,special builtins在三个方面不同于其它内置命令
1. Special builtins are found before shell functions during command lookup.
在命令检查期间,special builtins在shell 函数之前被发现。
2. If a special builtin returns an error status, a non-interactive shell exits.
假如一个special builtin 返回一个错误状态,一个非交互式shell退出。
3. Assignment statements preceding the command stay in effect in the shell environment after the command completes.
在命令完成之后的shell环境变量中,命令之前的赋值语句依然生效。
When Bash is not executing in posix mode, these builtins behave no differently than the rest of the Bash builtin commands. The Bash posix mode is described in Section 6.11 [Bash POSIX Mode], page 94.
当Bash不在posix模式下执行时,这些builtins表现与其余的bash内置命令没有什么不同。bash posix 模式在6.11部分[Bash POSIX Mode],94页中描述。
These are the posix special builtins:
break : . continue eval exec exit export readonly return set shift trap unset
 
 
9.3 History Expansion
 
The History library provides a history expansion feature that is similar to the history expansion provided by csh.
历史库提供一个与csh提供的历史扩展相似的历史扩展特性。
This section describes the syntax used to manipulate the history information.
这部分描述了用来维护历史信息的语法。

History expansions introduce words from the history list into the input stream, making it easy to repeat commands, insert the arguments to a previous command into the current input line, or fix errors in previous commands quickly.
历史扩展从历史列表中引进单词到输入流中,使重复命令,插入前一个命令的参数到当前输入行,或者快速修正前一个命令的错误变得简单。

History expansion takes place in two parts.
The first is to determine which line from the history list should be used during substitution.
首先侦测在替换期间,历史列表中的哪一行应该被使用。
The second is to select portions of that line for inclusion into the current one.
第二选择想要包含进当前行的哪一部分。
The line selected from the history is called the event, and the portions of that line that are acted upon are called words.
来自历史的选择行被叫做event,起作用的那部分行被叫做words。
Various modifiers are available to manipulate the selected words.
用来维护选择单词的多种修改器可用。
The line is broken into words in the same fashion that Bash does, so that several words surrounded by quotes are considered one word.
以便被引号包围的单词被认为是一个word。
History expansions are introduced by the appearance of the history expansion character, which is ‘!’ by default. Only ‘\’ and ‘'’ may be used to escape the history expansion character.
默认的历史扩展字符!的出现意味着历史扩展的开始。只有\和'可以被用来转义历史扩展字符。

Several shell options settable with the shopt builtin (see Bash Builtins) may be used to tailor the behavior of history expansion.
由shopt内置设置的一些shell选项可以被用来裁剪历史扩展的行为。
If the histverify shell option is enabled, and Readline is being used, history substitutions are not immediately passed to the shell parser.
如果histverify shell选项启用,并且readline正在被使用,历史替换不会立刻传递给shell解析。
Instead, the expanded line is reloaded into the Readline editing buffer for further modification.
替代,为了更进一步的修改,扩展行被重新载入到readline编辑缓冲。
If Readline is being used, and the histreedit shell option is enabled, a failed history expansion will be reloaded into the Readline editing buffer for correction.
The -p option to the history builtin command may be used to see what a history expansion will do before using it.
The -s option to the history builtin may be used to add commands to the end of the history list without actually executing them, so that they are available for subsequent recall.
This is most useful in conjunction with Readline.

The shell allows control of the various characters used by the history expansion mechanism with the histchars variable, as explained above (see Bash Variables).
The shell uses the history comment character to mark history timestamps when writing the history file.
 
3.4.2 Special Parameters

The shell treats several parameters specially. These parameters may only be referenced; assignment to them is not allowed.
shell特别对待一些参数。这些参数只能被引用,不允许赋值给它们。
($*) Expands to the positional parameters, starting from one. When the expansion is not within double quotes, each positional parameter expands to a separate word.
$*扩展位置参数,从一开始。当扩展不在双引号里时,每一个位置参数扩展为一个独立的单词。
In contexts where it is performed, those words are subject to further word splitting and pathname expansion.
When the expansion occurs within double quotes, it expands to a single word with the value of each parameter separated by the first character of the IFS special variable.
当扩展发生在双引号里时,它扩展为单个由IFS特殊变量第一个字符分隔的单词并附带每个参数的值。
That is, "$*" is equivalent to "$1c$2c…", where c is the first character of the value of the IFS variable. If IFS is unset, the parameters are separated by spaces.
就是说,$*等于"$1c$2c...",c是IFS变量值的第一个字符。如果IFS未设,参数由空格分隔。
If IFS is null, the parameters are joined without intervening separators.
如果IFS是空,参数连在一起没有中间分隔符。

($@) Expands to the positional parameters, starting from one. When the expansion occurs within double quotes, each parameter expands to a separate word.
$*扩展位置参数,从一开始。当扩展发生在双引号里时,每一个参数扩展为一个独立的单词。
That is, "$@" is equivalent to "$1" "$2" ….
If the double-quoted expansion occurs within a word, the expansion of the first parameter is joined with the beginning part of the original word, and the expansion of the last parameter is joined with the last part of the original word.
如果双引呈扩展发生在一个单词里,第一个参数
When there are no positional parameters, "$@" and $@ expand to nothing (i.e., they are removed).
当没有位置参数时,
 
3.5.3 Shell Parameter Expansion
The ‘$’ character introduces parameter expansion, command substitution, or arithmetic expansion.
$字符引入参数扩展,命令替换,算术扩展。
The parameter name or symbol to be expanded may be enclosed in braces,
被扩展的参数名或者符号可以用大括号封闭,
which are optional but serve to protect the variable to be expanded from characters immediately following it which could be interpreted as part of the name.
大括号是可选的但用来保护被扩展的变量
When braces are used, the matching ending brace is the first ‘}’ not escaped by a backslash or within a quoted string,
当大括号使用时,匹配结束括号是第一个},不用反斜线转义或引用,
and not within an embedded arithmetic expansion, command substitution, or parameter expansion.
不在内嵌的算术扩展,命令替换,或参数扩展。
The basic form of parameter expansion is ${parameter}. The value of parameter is substituted.
参数扩展的基本形式是${parameter}。参数值被替换。
The parameter is a shell parameter as described above (see Shell Parameters) or an array reference (see Arrays).
参数是一个如上所述的shell参数或一个数组引用。
The braces are required when parameter is a positional parameter with more than one digit, or when parameter is followed by a character that is not to be interpreted as part of its name.
当参数是一个多于一位数字的位置参数,或者当参数跟随一个不会被翻译为它名字一部分的字符时,需要大括号。
If the first character of parameter is an exclamation point (!), it introduces a level of variable indirection.
假如参数的第一个字符是一个感叹号,引入了一层间接变量。
Bash uses the value of the variable formed from the rest of parameter as the name of the variable;
bash使用参数其余部分构成的变量值做为变量名。
this variable is then expanded and that value is used in the rest of the substitution, rather than the value of parameter itself.
这个变量然后被扩展,并且它的值用作替换的其余部分,而不是参数值本身。
This is known as indirect expansion. The exceptions to this are the expansions of ${!prefix*} and ${!name[@]} described below.
这就是著名的间接扩展。这种扩展有两种异常描述如下:${!prefix*} and ${!name[@]}
The exclamation point must immediately follow the left brace in order to introduce indirection.
感叹号必须紧跟左括号为了引入间接。
In each of the cases below, word is subject to tilde expansion, parameter expansion, command substitution, and arithmetic expansion.
在下面每一种情况下,
When not performing substring expansion, using the form described below (e.g., ‘:-’), Bash tests for a parameter that is unset or null.
当没有完成子字符串扩展时,使用下面描述的形式,bash测试一个参数是撤销还是空的。
Omitting the colon results in a test only for a parameter that is unset. Put another way,
无冒号,只测试参数是撤销。换句话说,
if the colon is included, the operator tests for both parameter’s existence and that its value is not null;
if the colon is omitted, the operator tests only for existence.
有冒号,既测参数存在,还有值非空;无冒号,只测是否存在。
 
 
http://blog.csdn.net/ablo_zhou/article/details/5661730    这是翻译参考

3.5.1 Brace Expansion

Brace expansion is a mechanism by which arbitrary strings may be generated.
Brace expansion 是一种可能产生任意字符串的机制。
This mechanism is similar to filename expansion (see Filename Expansion), but the filenames generated need not exist.
这种机制类似于pathname expansion,但是并不需要存在相应的文件。
Patterns to be brace expanded take the form of an optional preamble, followed by either a series of comma-separated strings or a sequence expression between a pair of braces, followed by an optional postscript.
花括号扩展的模式是一个可选的preamble(前导字符),后面跟着一系列逗号分隔的字符串,包含在一对花括号中,
The preamble is prefixed to each string contained within the braces, and the postscript is then appended to each resulting string, expanding left to right.

Brace expansions may be nested. The results of each expanded string are not sorted; left to right order is preserved. For example,

bash$ echo a{d,c,b}e
ade ace abe
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值