Linux - Advanced Bash Shell Scripting Guide.pdf
(
4708 KB
)
Pobierz
Advanced Bash-Scripting Guide
Advanced Bash-Scripting Guide
Advanced Bash-Scripting Guide
An in-depth exploration of the gentle art of
shell scripting
Mendel Cooper
Brindle-Phlogiston Associates
thegrendel@theriver.com
16 June 2002
Revision History
Revision 0.1
14 June 2000
Revised by: mc
Initial release.
Revision 0.2 30 October 2000 Revised by: mc
Bugs fixed, plus much additional material and more example scripts.
Revision 0.3
12 February 2001
Revised by: mc
Another major update.
Revision 0.4 08 July 2001 Revised by: mc
More bugfixes, much more material, more scripts - a complete revision and expansion of
the book.
Revision 0.5 03 September 2001 Revised by: mc
Major update. Bugfixes, material added, chapters and sections reorganized.
Revision 1.0
14 October 2001
Revised by: mc
Bugfixes, reorganization, material added. Stable release.
Revision 1.1
06 January 2002
Revised by: mc
Bugfixes, material and scripts added.
Revision 1.2
31 March 2002
Revised by: mc
Bugfixes, material and scripts added.
Revision 1.3
02 June 2002
Revised by: mc
http://tldp.org/LDP/abs/html/ (1 of 11) [7/15/2002 6:33:43 PM]
Advanced Bash-Scripting Guide
'TANGERINE' release: A few bugfixes, much more material and scripts added.
Revision 1.4 16 June 2002 Revised by: mc
'MANGO' release: Quite a number of typos fixed, more material and scripts added.
This tutorial assumes no previous knowledge of scripting or programming, but progresses
rapidly toward an intermediate/advanced level of instruction
...all the while sneaking in little
snippets of UNIX wisdom and lore
. It serves as a textbook, a manual for self-study, and a
reference and source of knowledge on shell scripting techniques. The exercises and heavily-
commented examples invite active reader participation, under the premise that
the only
way to really learn scripting is to write scripts
.
The latest update of this document, as an archived,
bzip2-ed
"tarball" including both the
SGML source and rendered HTML, may be downloaded from
the author's home site
. See
the
change log
for a revision history.
Dedication
For Anita, the source of all the magic
Table of Contents
Part 1.
Introduction
1.
Why Shell Programming?
2.
Starting Off With a Sha-Bang
Part 2.
Basics
3.
Exit and Exit Status
4.
Special Characters
5.
Introduction to Variables and Parameters
6.
Quoting
7.
Tests
8.
Operations and Related Topics
Part 3.
Beyond the Basics
9.
Variables Revisited
10.
Loops and Branches
11.
Internal Commands and Builtins
http://tldp.org/LDP/abs/html/ (2 of 11) [7/15/2002 6:33:43 PM]
Advanced Bash-Scripting Guide
12.
External Filters, Programs and Commands
13.
System and Administrative Commands
14.
Command Substitution
15.
Arithmetic Expansion
16.
I/O Redirection
17.
Here Documents
18.
Recess Time
Part 4.
Advanced Topics
19.
Regular Expressions
20.
Subshells
21.
Restricted Shells
22.
Process Substitution
23.
Functions
24.
Aliases
25.
List Constructs
26.
Arrays
27.
Files
28.
/dev and /proc
29.
Of Zeros and Nulls
30.
Debugging
31.
Options
32.
Gotchas
33.
Scripting With Style
34.
Miscellany
35.
Bash, version 2
36.
Endnotes
36.1.
Author's Note
36.2.
About the Author
36.3.
Tools Used to Produce This Book
36.4.
Credits
Bibliography
A.
Contributed Scripts
B.
A Sed and Awk Micro-Primer
B.1.
Sed
B.2.
Awk
C.
Exit Codes With Special Meanings
http://tldp.org/LDP/abs/html/ (3 of 11) [7/15/2002 6:33:43 PM]
Advanced Bash-Scripting Guide
D.
A Detailed Introduction to I/O and I/O Redirection
E.
Localization
F.
History Commands
G.
A Sample
.bashrc
File
H.
Converting DOS Batch Files to Shell Scripts
I.
Exercises
I.1.
Analyzing Scripts
I.2.
Writing Scripts
J.
Copyright
List of Tables
11-1.
Job Identifiers
31-1.
bash options
B-1.
Basic sed operators
B-2.
Examples
C-1.
"Reserved" Exit Codes
H-1.
Batch file keywords / variables / operators, and their shell equivalents
H-2.
DOS Commands and Their UNIX Equivalents
List of Examples
2-1.
cleanup
: A script to clean up the log files in /var/log
2-2.
cleanup
: An enhanced and generalized version of above script.
3-1.
exit / exit status
3-2.
Negating a condition using !
4-1.
Code blocks and I/O redirection
4-2.
Saving the results of a code block to a file
4-3.
Running a loop in the background
4-4.
Backup of all files changed in last day
5-1.
Variable assignment and substitution
5-2.
Plain Variable Assignment
5-3.
Variable Assignment, plain and fancy
5-4.
Integer or string?
5-5.
Positional Parameters
5-6.
wh
, whois
domain name lookup
5-7.
Using
shift
6-1.
Echoing Weird Variables
http://tldp.org/LDP/abs/html/ (4 of 11) [7/15/2002 6:33:43 PM]
Advanced Bash-Scripting Guide
6-2.
Escaped Characters
7-1.
What is truth?
7-2.
Equivalence of test,
/usr/bin/test
, [ ], and
/usr/bin/[
7-3.
Arithmetic Tests using (( ))
7-4.
arithmetic and string comparisons
7-5.
testing whether a string is
null
7-6.
zmost
8-1.
Greatest common divisor
8-2.
Using Arithmetic Operations
8-3.
Compound Condition Tests Using && and ||
8-4.
Representation of numerical constants:
9-1.
$IFS and whitespace
9-2.
Timed Input
9-3.
Once more, timed input
9-4.
Timed
read
9-5.
Am I root?
9-6.
arglist
: Listing arguments with $* and $@
9-7.
Inconsistent
$*
and
$@
behavior
9-8.
$*
and
$@
when
$IFS
is empty
9-9.
underscore variable
9-10.
Converting graphic file formats, with filename change
9-11.
Alternate ways of extracting substrings
9-12.
Using param substitution and :
9-13.
Length of a variable
9-14.
Pattern matching in parameter substitution
9-15.
Renaming file extensions:
9-16.
Using pattern matching to parse arbitrary strings
9-17.
Matching patterns at prefix or suffix of string
9-18.
Using
declare
to type variables
9-19.
Indirect References
9-20.
Passing an indirect reference to
awk
9-21.
Generating random numbers
9-22.
Rolling the die with RANDOM
9-23.
Reseeding RANDOM
9-24.
Pseudorandom numbers, using awk
9-25.
C-type manipulation of variables
http://tldp.org/LDP/abs/html/ (5 of 11) [7/15/2002 6:33:43 PM]
Plik z chomika:
rav022
Inne pliki z tego folderu:
Zabezpieczenia w systemach linux.pdf
(567 KB)
Zaawansowane programowanie w systemie Linux [Helion 18 rozd.pdf
(25607 KB)
unixallwhatwasonlab.doc
(49 KB)
Unix For Dummies.pdf
(18060 KB)
Ubuntu Hacks - Tips And Tools For Exploring, Using, And Tuning Linux (O'reilly, 2006).pdf
(3566 KB)
Inne foldery tego chomika:
insrukcje do laptopów
instrukcje - inne
ksiązki o żaglowcach
matematyka, fizyka
medyczne
Zgłoś jeśli
naruszono regulamin