文件名称:
Bash_Guide_for_Beginners.pdf
开发工具:
文件大小: 1mb
下载次数: 0
上传时间: 2019-07-16
详细说明:Bash Guide for Beginners: The primary reason for writing this document is that a lot of readers feel the existing HOWTO to be too short
and incomplete, while the Bash Scripting guide is too much of a reference work. There is nothing in between
these two extremes. I also wrote this guide on the generBash guide for beginners
Table of contents
Chapter 3. The Bash environment..
3.1. Shell initialization files
29
1.1. System-wide configuration files...............................29
3.1.2. Individual user configuration files
31
313, Changing shell configuration files…………
33
32. Variab
34
3.2.1. Types of variables
34
3.2.2. Creating variables
37
2 3. Exporting variables.......
…138
3.2.4 Reserved variables
39
2.5. Special parameters.......,…….41
3.2.6. Script recycling with variables
43
3.3. Quoting characters
44
Yy
44
3.3.2. Escape characters..............,.,,,,,,,
·垂·,4音垂
3.3.3. Single quote,
45
3.3.4. Double quotes.......
45
33.5.ANSl- c quoting-………,,,,…,,…,…,…,…,,…………………,……….46
3.3.6. Locales
.46
3. 4. Shell expansion.....
146
3.41 General
垂面
4.2. Brace expansion
46
3. 4.3. Tilde expansion
47
3.4.4. Shell parameter and variable expansion
47
3.45. Command substitution
48
3. 4.6. Arithmetic expansion
49
3.47. Process substitution.
50
3.4.8. Word splitting..,.,.,.,,,,.,0
34.9. File name expansion……
3.5. Aliases
51
3.5.1. What are aliases?
51
3.5.2. Creating and removing aliases
音着垂音D·音音··,看,垂垂
52
36. More b3 ash options…………
3.6. 1. Displaying options
53
3.6.2. Changing options
54
37. Summary…………
55
8. Exercises
Chapter 4. Regular expressions...o..........
。。自。。
56
4.1. Regular expressions.
56
4.1. 1. What are regular expressions?
56
4.1.2. Regular expression metacharacters
56
4.1.3. Basic versus extended regular expressions......
57
4,2. Examples using grep.……….…….…………………157
4.2. 1. What is grep?
57
4.2.2.〔 Grep and regular expressions-…….….….….…...…
…58
43 Pattern matching using
4.3.1. Character ranges
··,音垂垂音音··
60
Bash Guide for Beginners
Table of contents
Chapter 4. Regular expressions
43.2 Character classes
60
4.4. Summary.............61
45. Exercises
61
Chapter 5. The gnu sed stream editor,oa.
鲁音自DD鲁自鲁自鲁鲁自D鲁D春曲。
62
51. Introduction
62
ed?
62
5.1.2. sed commands
…62
Interactive editing
5.2. 1. Printing lines containing a pattern
垂·看看4垂
63
5.2.2. Deleting lines of input containing a pattern
.64
52.3.Rangesoflineswwwwwwwwwwwwwwwwww.64
24. Find and replace with sed.………
65
53 Non-interactive editing
66
53.1. Reading sed commands from a file……
∴,66
5.3.2. Writing output fil
垂音垂
5. 4. Summary............
,67
5,5, Exercises.…
.68
Chapter 6. The gnu awk programming language.
6. 1. Getting started with gawk.
69
6.1.1. What is gawk?
.69
6.1.2, Gawk commands.
69
2. The print progran……
70
6.2.1. Printing selected fields
70
6.2 2. Formatting fields
71
6.2.3. The print command and regular expressions. .....72
6,24. Special patterns………
6.2. 5 Gawk scripts.......
···········
63. Gawk variables
73
631. The input field separator……
················
音着垂音D·音音··,看,垂垂
73
6.3.2. The output separators......
74
6. 3. The number of records
175
6.3. 4. User defined variables
75
6
..s. More examples.
76
6.3.6. The printf program
76
6.4. Summary
7
6.5. Exercises
………77
Chapter 7. Conditional statements
79
7.1. Introduction to if.
79
Genera
179
刁..2. Simple applications of if….82
7. 2. More advanced if usage
84
7.2.1 if/then/else constructs
84
7.2.2. if/then/elif/else constructs.......................87
7.2.3. Nested if statements
··,音垂垂音音··
88
Bash Guide for Beginners
Table of contents
Chapter 7. Conditional statements
7.2.4. Boolean operations…..........,,…
88
2.5, Using the exit statement and it.….….………,…,…,…,…,…,……………89
7.3. USing case statements,....................
90
7.3. 1 Simplified conditions
1.3.2. Initscript example
91
74. Summary……………
92
7. 5. Exercises
92
Chapter 8. Writing interactive scripts.....
94
8. 1. Displaying user messages.
8.1.1 Interactive or not
94
8. 1. 2. Using the echo built-in command
…94
8.2. Catching user input.……
97
8,2.1. Using the read built- in command....……………….97
8,2.2. Prompting for user input…………,…,………,…,…
98
8.2.3. Redirection and file descriptors
垂音垂
9
8,2.4. File input and output.…….….….….….….….….….….….……..………..101
8.3. Summary
105
8. 4. Exercises
Chapter 9. Repetitive
1. The for loop
.107
9.1.1. How does it work
垂··垂非
107
9.1.2. Examples
107
9.2. The while loop.......
108
9.2.1. What is it?
108
9.2.2. Examples....,.,.,.,,,.,,,,,108
9.3. The until loop
IlI
9.3. 1. What is it?
.··.······:.··.·
垂·看看4垂
93.2,上 xample…….….….….….….…,.….….….…….….….……….………….11
9.4. 1/0 redirection and loops
音着·音D·音音·,垂
112
4.1. Input redirection………
垂垂
112
9.4.2. Output redirect
112
9.5. Break and continue
9.5.1 The break built-in
113
9.5.2. The continue built-in
114
953. Examples…
114
9.6. Making menus with the select built-in
…………115
9.6.1. General
115
9.6.2. Submenus
垂··垂
117
9.7. The shift built -in
117
9.7.1. what does it do?
117
9.7.2. Examples.
…………117
8. summary
118
9.9. Exercises
119
Bash Guide for Beginners
Table of contents
Chapter 10. More on variables……
1120
0. 1. Types of variables..........................120
10.J.l. General assignment of values…….….….….….….….….….….….….….….…...20
10. 1.2, Using the declare built-in
120
10.13, Constants
121
0.2. Array variables ................ 122
10.2.1. Creating arrays
122
10.2.2. Dereferencing the variables in an array
122
10.2.3. Deleting array variables
123
0. 2. 4. Examples of arrays.
123
10.3. Operations on variables,.........
∴126
10.3.1. Arithmetic on variables
126
10.3.2. Length of a variable..................126
103.3. Transformations of variables
126
10.4. Summary.
···:·:··:··:·····:
129
10.5. Exercises………………
12
Chapter 1l., Functions.…..,,...,,.,,..,.,,..,,,.,,.,,,,130
130
11. 1. 1. what are function
130
11. 1. 2. Function synta
130
垂面
11.13. Positional parameters in functions………….….….….…………….131
11. 1. 4. Displaying functions
132
11.2. Examples of functions in scripts
132
11.2.1.R
132
11.2. 2. Setting the path
133
2.3. Remote backups.......
133
11.3. Summary
……………135
14. Exercises
垂·垂音垂垂音音·音·垂垂
135
Chapter 12. Catching
12.1. Signals
音着·音D·音音·,垂
136
12.L. 1. Introduction…………
垂垂
136
12.1.2. Usage of signals with kill.
137
12.2. Traps
……138
12.2.1 General
138
12.2.2. How Bash interprets traps
138
12.2.3. More examples
139
12.3. Summary
·.··:···········
…139
2.4.E
139
Appendix A, Shell features.....,...,…,………141
A 1. Common features.
…141
A. 2. Differing features.
………142
Appendix b. gnu free Documentation
B. 1. Preamble
145
B.2. Applicability and definitions…………………
··,音垂垂音音··
145
Bash Guide for Beginners
Table of contents
Appendix B GNU Free Documentation License
B.3. Verbatim copying
116
B.4. Copying in quantity
B 5. Modifications
147
B 6. Combining documents
148
B.7. Collections of documents
148
B.8.^ gregation with independent works.……
149
B 9. Translation
149
B 10. Termination.
……149
B. 11. Future revisions of this license
.149
B 12. How to use this License for your documents,..........
4垂
150
Glossary
00151
ABC
垂垂
l51
∴15
.151
D
152
E
……………………………,………………153
F
53
55
垂面
154
…………………154
154
K…
.·······.·························
…155
15
M.
156
156
·······,···················
157
Q
.·..····
157
R
157
158
工
158
垂垂
159
V
:··
159
160
Z
着垂
161
Index.mnsmmmmomnmmmm162
162
ABCD
.162
163
E
163
F
164
165
165
··,音垂垂音音··
165
Bash Guide for Beginners
Table of contents
Index
166
K.166
166
M
166
166
Q
167
P
167
Q...…
167
R
167
168
T
169
夏…....……169
垂垂
169
W
音·,d4番
170
170
170
170
Introduction
1. Why this guide?
The primary reason for writing this document is that a lot of readers feel the existing HOWto to be too short
and incomplete, while the Bash Scripting guide is too much of a reference work. There is nothing in between
these two extremes. I also wrote this guide on the general principal that not enough free basic courses are
available, though they should be
This is a practical guide which, while not always being too serious, tries to give real-life instead of theoretical
examples I partly wrote it because i dont get excited with stripped down and over-simplified examples
written by people who know what they are talking about, showing some really cool Bash feature so much out
of its context that you cannot ever use it in practical circumstances. You can read that sort of stuff after
finishing this book, which contains exercises and examples that will help you survive in the real world
From my experience as UNIX/Linux user, system administrator and trainer, I know that people can have years
often think that UNIX is not userfriendly, and even worse, they get the impression that it is slow anld us they
of daily interaction with their systems, without having the slightest knowledge of task automation. Tht
old-fashioned. This problem is another one that can be remedied by this guide
2 Who should read this book?
Everybody working on a uniX or uniX-like system who wants to make life easier on themselves, power
users and sysadmins alike, can benefit from reading this book Readers who already have a grasp of working
the system using the command line will learn the ins and outs of shell scripting that ease execution of daily
tasks. System administration relies a great deal on shell scripting; common tasks are often automated using
simple scripts. This document is full of examples that will encourage you to write your own and that will
Inspire you to improve on existing scripts
Prerequisites/not in this course
You should be an experienced UNIX or Linux user, familiar with basic commands, man pages and
documentation
o Being able to use a text editor
Understand system boot and shutdown processes, init and initscripts
o Create users and groups, set passwords
Permissions, special modes
e Understand naming conventions for devices, partitioning, mounting/unmounting file systems
Adding/removing software on your syste
See Introduction to Linux (or your local tLDP mirror) if you haven ' t mastered one or more of these topics
Additional information can be found in your system documentation(man and info pages), or at the linux
Documentation Project
Introduction
Bash guide for beginners
3. New versions and availability
Themostrecenteditioncanbefoundathttp:/tille.xalasys.com/training/bash/.Youshouldfindthesame
versionathttp://tldp.org/ldp/bash-begInnerS-guidE/htmvindex.html
ThisguideisavailableinprintfromFultus.com
Figure 1. Bash guide for Beginners front cover
Fultus
Machtelt garrels
in/bash guide
nsL工S
for
-o/tmp/a3
beginners
n15
Fultus Technica! Ubrary
4. Revision History
Revision history
Revision 1.7
2005-09-05
Revised by: MG
Corrected typos in chapter 3, 6 and 7, incorporated user remarks, added a note in chap
Revision 1.6
2005-03-01
Revised by: MG
Minor debugging, added more keywords, info about new Bash 3. 0, took out blank image
Revision 1.5
2004-12-06
Revised by: MG
Changes because of new domain minor corrections
Revision 1. 4
2004-10-18
Revised by: MG
Debugging, added a couple of notes in chap, replaced screenshots with screen sections. Corrected some
typ
Revision 1. 3
2004-07-09
Revised by: MG
Addedtracerimagelxlpixelhttp://tille.xalasys.com/images/blank-bash.png,addedtextobjectsforall
pictures, fixed wrong links in index, made signal list more clear.
Revision 1. 2
2004-06-15
Revised by: MG
Added index, more markup in screen sections
Revision 1.1
2004-05-22
Revised by: MG
Last read-through before going to press, added more examples, checked summaries, exercises, cleaned up
introduction
Revision 1.0
2004-04-27
Revised by: TM
Introduction
2
(系统自动生成,下载前可以参看下载内容)
下载文件列表
相关说明
- 本站资源为会员上传分享交流与学习,如有侵犯您的权益,请联系我们删除.
- 本站是交换下载平台,提供交流渠道,下载内容来自于网络,除下载问题外,其它问题请自行百度。
- 本站已设置防盗链,请勿用迅雷、QQ旋风等多线程下载软件下载资源,下载后用WinRAR最新版进行解压.
- 如果您发现内容无法下载,请稍后再次尝试;或者到消费记录里找到下载记录反馈给我们.
- 下载后发现下载的内容跟说明不相乎,请到消费记录里找到下载记录反馈给我们,经确认后退回积分.
- 如下载前有疑问,可以通过点击"提供者"的名字,查看对方的联系方式,联系对方咨询.