Albing - Bash Cookbook [unix shell programming] (O'Reilly, 2007).pdf
(
1952 KB
)
Pobierz
435730527 UNPDF
bash Cookbook
™
Carl Albing, JP Vossen, and Cameron Newham
Beijing
•
Cambridge
•
Farnham
•
Köln
•
Paris
•
Sebastopol
•
Taipei
•
Tokyo
bash Cookbook
™
by Carl Albing, JP Vossen, and Cameron Newham
Copyright © 2007 O’Reilly Media, Inc. All rights reserved.
Printed in the United States of America.
Published by O’Reilly Media, Inc., 1005 Gravenstein Highway North, Sebastopol, CA 95472.
O’Reilly books may be purchased for educational, business, or sales promotional use. Online editions
are also available for most titles (
safari.oreilly.com
). For more information, contact our
corporate/institutional sales department: (800) 998-9938 or
corporate@oreilly.com
.
Editor:
Mike Loukides
Production Editor:
Laurel R.T. Ruma
Copyeditor:
Derek Di Matteo
Production Services:
Tolman Creek Design
Cover Designer:
Karen Montgomery
Interior Designer:
David Futato
Illustrators:
Robert Romano and Jessamyn Read
Printing History:
May 2007:
First Edition.
Nutshell Handbook, the Nutshell Handbook logo, and the O’Reilly logo are registered trademarks of
O’ReillyMedia,Inc.
bash Cookbook
,theimageofawoodturtle,andrelatedtradedressaretrademarks
of O’Reilly Media, Inc.
Manyofthedesignationsusedbymanufacturersandsellerstodistinguishtheirproductsareclaimedas
trademarks. Where those designations appear in this book, and O’Reilly Media, Inc. was aware of a
trademark claim, the designations have been printed in caps or initial caps.
While every precaution has been taken in the preparation of this book, the publisher and authors
assume no responsibility for errors or omissions, or for damages resulting from the use of the
information contained herein.
This book uses RepKover
™
, a durable and flexible lay-flat binding.
ISBN 10: 0-596-52678-4
ISNB 13: 978-0-596-52678-8
[M]
Table of Contents
Preface
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
xiii
1. Beginning bash
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1
1.1 Decoding the Prompt
4
1.2 Showing Where You Are
5
1.3 Finding and Running Commands
6
1.4 Getting Information About Files
8
1.5 Showing All Hidden (dot) Files in the Current Directory
10
1.6 Using Shell Quoting
12
1.7 Using or Replacing Built-ins and External Commands
13
1.8 Determining If You Are Running Interactively
15
1.9 Setting bash As Your Default Shell
16
1.10 Getting bash for Linux
17
1.11 Getting bash for xBSD
20
1.12 Getting bash for Mac OS X
21
1.13 Getting bash for Unix
22
1.14 Getting bash for Windows
23
1.15 Getting bash Without Getting bash
24
1.16 Learning More About bash Documentation
25
2. Standard Output
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
28
2.1 Writing Output to the Terminal/Window
29
2.2 Writing Output but Preserving Spacing
30
2.3 Writing Output with More Formatting Control
31
2.4 Writing Output Without the Newline
32
2.5 Saving Output from a Command
33
2.6 Saving Output to Other Files
34
iii
2.7 Saving Output from the ls Command
35
2.8 Sending Both Output and Error Messages to Different Files
37
2.9 Sending Both Output and Error Messages to the Same File
37
2.10 Appending Rather Than Clobbering Output
39
2.11 Using Just the Beginning or End of a File
39
2.12 Skipping a Header in a File
40
2.13 Throwing Output Away
41
2.14 Saving or Grouping Output from Several Commands
41
2.15 Connecting Two Programs by Using Output As Input
43
2.16 Saving a Copy of Output Even While Using It As Input
44
2.17 Connecting Two Programs by Using Output As Arguments
46
2.18 Using Multiple Redirects on One Line
47
2.19 Saving Output When Redirect Doesn’t Seem to Work
48
2.20 Swapping STDERR and STDOUT
50
2.21 Keeping Files Safe from Accidental Overwriting
52
2.22 Clobbering a File on Purpose
53
3. Standard Input
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
55
3.1 Getting Input from a File
55
3.2 Keeping Your Data with Your Script
56
3.3 Preventing Weird Behavior in a Here-Document
57
3.4 Indenting Here-Documents
59
3.5 Getting User Input
60
3.6 Getting Yes or No Input
61
3.7 Selecting from a List of Options
64
3.8 Prompting for a Password
65
4. Executing Commands
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
67
4.1 Running Any Executable
67
4.2 Telling If a Command Succeeded or Not
69
4.3 Running Several Commands in Sequence
71
4.4 Running Several Commands All at Once
72
4.5 Deciding Whether a Command Succeeds
74
4.6 Using Fewer if Statements
75
4.7 Running Long Jobs Unattended
76
4.8 Displaying Error Messages When Failures Occur
77
4.9 Running Commands from a Variable
78
4.10 Running All Scripts in a Directory
79
iv
|
Table of Contents
5. Basic Scripting: Shell Variables
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
80
5.1 Documenting Your Script
82
5.2 Embedding Documentation in Shell Scripts
83
5.3 Promoting Script Readability
85
5.4 Separating Variable Names from Surrounding Text
86
5.5 Exporting Variables
87
5.6 Seeing All Variable Values
89
5.7 Using Parameters in a Shell Script
90
5.8 Looping Over Arguments Passed to a Script
91
5.9 Handling Parameters with Blanks
92
5.10 Handling Lists of Parameters with Blanks
94
5.11 Counting Arguments
96
5.12 Consuming Arguments
98
5.13 Getting Default Values
99
5.14 Setting Default Values
100
5.15 Using null As a Valid Default Value
101
5.16 Using More Than Just a Constant String for Default
102
5.17 Giving an Error Message for Unset Parameters
103
5.18 Changing Pieces of a String
105
5.19 Using Array Variables
106
6. Shell Logic and Arithmetic
. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
108
6.1 Doing Arithmetic in Your Shell Script
108
6.2 Branching on Conditions
111
6.3 Testing for File Characteristics
114
6.4 Testing for More Than One Thing
117
6.5 Testing for String Characteristics
118
6.6 Testing for Equal
119
6.7 Testing with Pattern Matches
121
6.8 Testing with Regular Expressions
122
6.9 Changing Behavior with Redirections
125
6.10 Looping for a While
126
6.11 Looping with a read
128
6.12 Looping with a Count
130
6.13 Looping with Floating-Point Values
131
6.14 Branching Many Ways
132
6.15 Parsing Command-Line Arguments
134
6.16 Creating Simple Menus
137
Table of Contents
v
|
Plik z chomika:
walbo48
Inne pliki z tego folderu:
Cole - Planetary Science - Science of Planets Around Stars (IOP, 2002).pdf
(8299 KB)
Einstein's Space-Time - An Intro to Special and General Relativity - R. Ferraro (Springer, 2007) WW.pdf
(8617 KB)
Frolov - Black Hole Physics - Basic Concepts and New Developments (Kluwer, 1997).pdf
(26556 KB)
Falcke - The Galactic Black Hole (IOP, 2003).pdf
(19940 KB)
Elements of Space Technology - R. Meyer (AP, 1999) WW.djvu
(2924 KB)
Inne foldery tego chomika:
ksiazki
Schematy spawarek
Amaterske Radio_2009.rar
))) Przyśpiewki weselne
@Excel
Zgłoś jeśli
naruszono regulamin