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

Advanced Bash-Scripting Guide

Ratings:

4.4

(10)
|Views: 2,786|Likes:
Published by ramesh2440
linux bash script
linux bash script

More info:

Published by: ramesh2440 on Jan 29, 2009
Copyright:Attribution Non-commercial

Availability:

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

05/10/2014

 
Advanced Bash−Scripting Guide
An in−depth exploration of the art of shell scripting
Mendel Cooper
<thegrendel@theriver.com>
2.811 July 2004
Revision History
Revision 2.515 February 2004Revised by: mc'STARFRUIT' release: Bugfixes and more material.Revision 2.615 March 2004Revised by: mc'SALAL' release: Minor update.Revision 2.718 April 2004Revised by: mc'MULBERRY' release: Minor 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 snippets 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 to programming 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. See thechange 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..................................................................................25
4.1. Variable Substitution......................................................................................................................254.2. Variable Assignment.......................................................................................................................274.3. Bash Variables Are Untyped..........................................................................................................284.4. Special Variable Types...................................................................................................................30
Chapter 5. Quoting...........................................................................................................................................34Chapter 6. Exit and Exit Status.......................................................................................................................40Chapter 7. Tests................................................................................................................................................42
7.1. Test Constructs...............................................................................................................................427.2. File test operators............................................................................................................................487.3. Other Comparison Operators..........................................................................................................517.4. Nested if/then Condition Tests.......................................................................................................567.5. Testing Your Knowledgeof Tests..................................................................................................56
Chapter 8. Operations and Related Topics....................................................................................................58
8.1. Operators.........................................................................................................................................588.2. Numerical Constants.......................................................................................................................64
Part 3. Beyond the Basics.................................................................................................................................66Chapter 9. Variables Revisited........................................................................................................................67
9.1. Internal Variables............................................................................................................................679.2. Manipulating Strings.......................................................................................................................839.2.1. Manipulating strings using awk............................................................................................879.2.2. Further Discussion.................................................................................................................889.3. Parameter Substitution....................................................................................................................889.4. Typing variables: declare or typeset...............................................................................................979.5. Indirect References to Variables.....................................................................................................989.6. $RANDOM: generate random integer..........................................................................................1009.7. The DoubleParenthesesConstruct...............................................................................................109
Chapter 10. Loops andBranches..................................................................................................................111
10.1. Loops..........................................................................................................................................11110.2. Nested Loops..............................................................................................................................12210.3. Loop Control...............................................................................................................................122
Advanced Bash−Scripting Guidei
 
Table ofContents
Chapter 10. Loops and Branches
10.4. Testing and Branching................................................................................................................126
Chapter 11. Internal Commands and Builtins.............................................................................................133
11.1. Job Control Commands..............................................................................................................155
Chapter 12. External Filters, Programs and Commands...........................................................................160
12.1. Basic Commands........................................................................................................................16012.2. Complex Commands...................................................................................................................16412.3. Time / Date Commands..............................................................................................................17312.4. Text Processing Commands........................................................................................................17612.5. File and Archiving Commands...................................................................................................19312.6. Communications Commands......................................................................................................20712.7. Terminal Control Commands.....................................................................................................21212.8. Math Commands.........................................................................................................................21312.9. Miscellaneous Commands..........................................................................................................222
Chapter 13. System and Administrative Commands..................................................................................233Chapter 14. Command Substitution.............................................................................................................257Chapter 15. ArithmeticExpansion................................................................................................................262Chapter 16. I/O Redirection...........................................................................................................................263
16.1. Using exec...................................................................................................................................26516.2. Redirecting Code Blocks............................................................................................................26816.3. Applications................................................................................................................................272
Chapter 17. Here Documents.........................................................................................................................274Chapter 18. Recess Time................................................................................................................................283Part 4. Advanced Topics.................................................................................................................................284Chapter 19. Regular Expressions..................................................................................................................285
19.1. ABrief Introduction to Regular Expressions..............................................................................28519.2. Globbing.....................................................................................................................................288
Chapter 20. Subshells.....................................................................................................................................290Chapter 21. Restricted Shells.........................................................................................................................293Chapter 22. Process Substitution...................................................................................................................295Chapter 23. Functions....................................................................................................................................297
23.1. Complex Functions and Function Complexities.........................................................................29923.2. Local Variables...........................................................................................................................30823.2.1. Local variables help make recursion possible...................................................................310
Advanced Bash−Scripting Guideii

Activity (3)

You've already reviewed this. Edit your review.
1 hundred reads
1 thousand reads
roupasvas liked this

You're Reading a Free Preview

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