没有合适的资源?快使用搜索试试~ 我知道了~
bash reference doc PDF
资源推荐
资源详情
资源评论
Bash Reference Manual
Reference Documentation for Bash
Edition 4.0, for Bash Version 4.0.
February 2009
Chet Ramey, Case Western Reserve University
Brian Fox, Free Software Foundation
This text is a brief description of the features that are present in the Bash shell (version
4.0, 13 February 2009).
This is Edition 4.0, last updated 13 February 2009, of The GNU Bash Reference Manual,
for Bash, Version 4.0.
Copyright
c
° 1988–2009 Free Software Foundation, Inc.
Permission is granted to make and distribute verbatim copies of this manual provided the
copyright notice and this permission notice are preserved on all copies.
Permission is granted to copy, distribute and/or modify this document under
the terms of the GNU Free Documentation License, Version 1.2 or any later
version published by the Free Software Foundation; with no Invariant Sections,
with the Front-Cover texts being “A GNU Manual”, and with the Back-Cover
Texts as in (a) below. A copy of the license is included in the section entitled
“GNU Free Documentation License”.
(a) The FSF’s Back-Cover Text is: You are free to copy and modify this GNU
manual. Buying copies from GNU Press supports the FSF in developing GNU
and promoting software freedom.”
Published by the Free Software Foundation
59 Temple Place, Suite 330,
Boston, MA 02111-1307
USA
i
Table of Contents
1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.1 What is Bash? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
1.2 What is a shell? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1
2 Definitions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
3 Basic Shell Features. . . . . . . . . . . . . . . . . . . . . . . . 5
3.1 Shell Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.1.1 Shell Operation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.1.2 Quoting. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
3.1.2.1 Escape Character . . . . . . . . . . . . . . . . . . . . . . 6
3.1.2.2 Single Quotes . . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.1.2.3 Double Quotes . . . . . . . . . . . . . . . . . . . . . . . . . 6
3.1.2.4 ANSI-C Quoting . . . . . . . . . . . . . . . . . . . . . . . 6
3.1.2.5 Locale-Specific Translation. . . . . . . . . . . . . . 7
3.1.3 Comments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.2 Shell Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3.2.1 Simple Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.2.2 Pipelines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.2.3 Lists of Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.2.4 Compound Commands . . . . . . . . . . . . . . . . . . . . . . . . . . 9
3.2.4.1 Looping Constructs . . . . . . . . . . . . . . . . . . . . 9
3.2.4.2 Conditional Constructs . . . . . . . . . . . . . . . . 10
3.2.4.3 Grouping Commands . . . . . . . . . . . . . . . . . . 13
3.2.5 Coprocesses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.3 Shell Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14
3.4 Shell Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.4.1 Positional Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.4.2 Special Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
3.5 Shell Expansions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
3.5.1 Brace Expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
3.5.2 Tilde Expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
3.5.3 Shell Parameter Expansion . . . . . . . . . . . . . . . . . . . . . 20
3.5.4 Command Substitution . . . . . . . . . . . . . . . . . . . . . . . . 22
3.5.5 Arithmetic Expansion . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.5.6 Process Substitution . . . . . . . . . . . . . . . . . . . . . . . . . . . 23
3.5.7 Word Splitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.5.8 Filename Expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
3.5.8.1 Pattern Matching . . . . . . . . . . . . . . . . . . . . . 25
3.5.9 Quote Removal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.6 Redirections . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
3.6.1 Redirecting Input. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
ii Bash Reference Manual
3.6.2 Redirecting Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27
3.6.3 Appending Redirected Output . . . . . . . . . . . . . . . . . . 27
3.6.4 Redirecting Standard Output and Standard Error
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
3.6.5 Appending Standard Output and Standard Error
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
3.6.6 Here Documents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 28
3.6.7 Here Strings. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.6.8 Duplicating File Descriptors . . . . . . . . . . . . . . . . . . . . 29
3.6.9 Moving File Descriptors . . . . . . . . . . . . . . . . . . . . . . . . 29
3.6.10 Opening File Descriptors for Reading and Writing
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29
3.7 Executing Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
3.7.1 Simple Command Expansion . . . . . . . . . . . . . . . . . . . 30
3.7.2 Command Search and Execution . . . . . . . . . . . . . . . . 30
3.7.3 Command Execution Environment . . . . . . . . . . . . . . 31
3.7.4 Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
3.7.5 Exit Status. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
3.7.6 Signals. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
3.8 Shell Scripts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
4 Shell Builtin Commands . . . . . . . . . . . . . . . . . . 35
4.1 Bourne Shell Builtins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
4.2 Bash Builtin Commands . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
4.3 Modifying Shell Behavior . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
4.3.1 The Set Builtin. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
4.3.2 The Shopt Builtin . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
4.4 Special Builtins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 59
5 Shell Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
5.1 Bourne Shell Variables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
5.2 Bash Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
6 Bash Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
6.1 Invoking Bash . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
6.2 Bash Startup Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
6.3 Interactive Shells . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
6.3.1 What is an Interactive Shell? . . . . . . . . . . . . . . . . . . . 75
6.3.2 Is this Shell Interactive?. . . . . . . . . . . . . . . . . . . . . . . . 75
6.3.3 Interactive Shell Behavior . . . . . . . . . . . . . . . . . . . . . . 75
6.4 Bash Conditional Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . 76
6.5 Shell Arithmetic . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78
6.6 Aliases . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
6.7 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 80
6.8 The Directory Stack . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
6.8.1 Directory Stack Builtins. . . . . . . . . . . . . . . . . . . . . . . . 82
6.9 Controlling the Prompt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83
iii
6.10 The Restricted Shell. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
6.11 Bash POSIX Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
7 Job Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
7.1 Job Control Basics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
7.2 Job Control Builtins. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 90
7.3 Job Control Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
8 Command Line Editing . . . . . . . . . . . . . . . . . . . 93
8.1 Introduction to Line Editing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
8.2 Readline Interaction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
8.2.1 Readline Bare Essentials . . . . . . . . . . . . . . . . . . . . . . . 93
8.2.2 Readline Movement Commands . . . . . . . . . . . . . . . . . 94
8.2.3 Readline Killing Commands . . . . . . . . . . . . . . . . . . . . 94
8.2.4 Readline Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
8.2.5 Searching for Commands in the History . . . . . . . . . 95
8.3 Readline Init File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
8.3.1 Readline Init File Syntax. . . . . . . . . . . . . . . . . . . . . . . 96
8.3.2 Conditional Init Constructs . . . . . . . . . . . . . . . . . . . 102
8.3.3 Sample Init File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
8.4 Bindable Readline Commands. . . . . . . . . . . . . . . . . . . . . . . . . . 106
8.4.1 Commands For Moving . . . . . . . . . . . . . . . . . . . . . . . 106
8.4.2 Commands For Manipulating The History . . . . . . 107
8.4.3 Commands For Changing Text . . . . . . . . . . . . . . . . 108
8.4.4 Killing And Yanking . . . . . . . . . . . . . . . . . . . . . . . . . . 109
8.4.5 Specifying Numeric Arguments . . . . . . . . . . . . . . . . 110
8.4.6 Letting Readline Type For You . . . . . . . . . . . . . . . . 110
8.4.7 Keyboard Macros. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
8.4.8 Some Miscellaneous Commands. . . . . . . . . . . . . . . . 112
8.5 Readline vi Mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114
8.6 Programmable Completion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
8.7 Programmable Completion Builtins. . . . . . . . . . . . . . . . . . . . . 116
9 Using History Interactively. . . . . . . . . . . . . . . 121
9.1 Bash History Facilities. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
9.2 Bash History Builtins. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
9.3 History Expansion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
9.3.1 Event Designators . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
9.3.2 Word Designators . . . . . . . . . . . . . . . . . . . . . . . . . . . . 124
9.3.3 Modifiers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 125
剩余163页未读,继续阅读
资源评论
thinkinwm
- 粉丝: 340
- 资源: 10
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功