Welcome to Scribd, the world's digital library. Read, publish, and share books and documents. See more
Download
Standard view
Full view
of .
Look up keyword
Like this
3Activity
0 of .
Results for:
No results containing your search query
P. 1
Advanced Bash-Scripting Guide July 2008

Advanced Bash-Scripting Guide July 2008

Ratings: (0)|Views: 35|Likes:
Published by jawwad983

More info:

Published by: jawwad983 on Jan 19, 2010
Copyright:Attribution Non-commercial

Availability:

Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less

07/07/2010

pdf

text

original

 
Advanced Bash-Scripting Guide
An in-depth exploration of the art of shell scripting
Mendel Cooper
<thegrendel@theriver.com>
5.421 July 2008
Revision History
Revision 5.216 Mar 2008Revised by: mc'SILVERBERRY' release: Important Update.Revision 5.305 May 2008Revised by: mc'GOLDENBERRY' release: Minor Update.Revision 5.421 July 2008Revised by: mc'ANGLEBERRY' release: Major Update.This tutorial assumes no previous knowledge of scripting or programming, but progresses rapidly toward anintermediate/advanced level of instruction
. . . all the while sneaking in little nuggets of UNIX® wisdom and lore
. It serves as a textbook, a manual for self-study, and a reference and source of knowledge on shellscripting techniques. The exercises and heavily-commented examples invite active reader participation, underthe premise that
the only way to really learn scripting is to write scripts
.This book is suitable for classroom use as a general introduction toprogramming concepts. The latest update of this document, as an archived, bzip2-ed "tarball" including both the SGML source andrendered HTML, may be downloaded from the author's home site. A pdf version is also available ( pdf mirrorsite). See the change log for a revision history.
Dedication
For Anita, the source of all the magic
 
Table of Contents
Chapter 1. Why Shell Programming?...............................................................................................................1Chapter 2. Starting Off With a Sha-Bang........................................................................................................3
2.1. Invoking the script............................................................................................................................62.2. Preliminary Exercises.......................................................................................................................6
Part 2. Basics.......................................................................................................................................................7Chapter 3. Special Characters...........................................................................................................................8Chapter 4. Introduction to Variables and Parameters..................................................................................28
4.1. Variable Substitution......................................................................................................................284.2. Variable Assignment.......................................................................................................................314.3. Bash Variables Are Untyped..........................................................................................................324.4. Special Variable Types...................................................................................................................33
Chapter 5. Quoting...........................................................................................................................................39
5.1. Quoting Variables...........................................................................................................................395.2. Escaping..........................................................................................................................................41
Chapter 6. Exit and Exit Status.......................................................................................................................46Chapter 7. Tests................................................................................................................................................48
7.1. Test Constructs...............................................................................................................................487.2. File test operators............................................................................................................................557.3. Other Comparison Operators..........................................................................................................587.4. Nestedif/then Condition Tests.......................................................................................................637.5. Testing Your Knowledgeof Tests..................................................................................................64
Chapter 8. Operations and Related Topics....................................................................................................65
8.1. Operators.........................................................................................................................................658.2. Numerical Constants.......................................................................................................................71
Part 3. Beyond the Basics.................................................................................................................................73Chapter 9. Variables Revisited........................................................................................................................74
9.1. Internal Variables............................................................................................................................749.2. Manipulating Strings.......................................................................................................................919.2.1. Manipulating strings using awk............................................................................................989.2.2. Further Reference..................................................................................................................999.3. Parameter Substitution....................................................................................................................999.4. Typing variables: declare or typeset.............................................................................................1089.5. Indirect References.......................................................................................................................1109.6. $RANDOM: generate random integer..........................................................................................1149.7. The Double-Parentheses Construct...............................................................................................125
Advanced Bash-Scripting Guidei
 
Table of Contents
Chapter 10. Loops andBranches..................................................................................................................127
10.1. Loops..........................................................................................................................................12710.2. Nested Loops..............................................................................................................................14010.3. Loop Control...............................................................................................................................14110.4. Testing and Branching................................................................................................................144
Chapter 11. Command Substitution.............................................................................................................152Chapter 12. Arithmetic Expansion................................................................................................................158Chapter 13. Recess Time................................................................................................................................159Part 4. Commands..........................................................................................................................................160Chapter 14. Internal Commands and Builtins.............................................................................................168
14.1. Job Control Commands..............................................................................................................196
Chapter 15. External Filters, Programs and Commands...........................................................................201
15.1. Basic Commands........................................................................................................................20115.2. Complex Commands...................................................................................................................20615.3. Time / Date Commands..............................................................................................................21615.4. Text Processing Commands........................................................................................................22015.5. File and Archiving Commands...................................................................................................24215.6. Communications Commands......................................................................................................25915.7. Terminal Control Commands.....................................................................................................27315.8. Math Commands.........................................................................................................................27415.9. Miscellaneous Commands..........................................................................................................285
Chapter 16. System and AdministrativeCommands..................................................................................299
16.1. Analyzing a System Script..........................................................................................................328
Part 5. Advanced Topics.................................................................................................................................330Chapter 17. Regular Expressions..................................................................................................................332
17.1. ABrief Introduction to Regular Expressions..............................................................................33217.2. Globbing.....................................................................................................................................335
Chapter 18. Here Documents.........................................................................................................................337
18.1. Here Strings................................................................................................................................347
Chapter 19. I/O Redirection...........................................................................................................................350
19.1. Using exec...................................................................................................................................35319.2. Redirecting Code Blocks............................................................................................................35619.3. Applications................................................................................................................................361
Chapter 20. Subshells.....................................................................................................................................363
Advanced Bash-Scripting Guideii

You're Reading a Free Preview

Download
scribd
/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->