Example: marketing

Advanced Bash-Scripting Guide - UV

Advanced bash scripting GuideAn in depth exploration of the gentle art of shell scriptingMendel CooperBrindle Phlogiston July 2002 Revision HistoryRevision June 2000 Revised by: mcInitial October 2000 Revised by: mcBugs fixed, plus much additional material and more example February 2001 Revised by: mcAnother major July 2001 Revised by: mcMore bugfixes, much more material, more scripts a complete revision and expansion of the September 2001 Revised by: mcMajor update. Bugfixes, material added, chapters and sections October 2001 Revised by: mcBugfixes, reorganization, material added.

Advanced Bash−Scripting Guide An in−depth exploration of the gentle art of shell scripting Mendel Cooper Brindle−Phlogiston Associates thegrendel@theriver.com

Tags:

  Guide, Advanced, Bash, Scripting, Advanced bash scripting guide

Information

Domain:

Source:

Link to this page:

Please notify us if you found a problem with this document:

Other abuse

Advertisement

Transcription of Advanced Bash-Scripting Guide - UV

1 Advanced bash scripting GuideAn in depth exploration of the gentle art of shell scriptingMendel CooperBrindle Phlogiston July 2002 Revision HistoryRevision June 2000 Revised by: mcInitial October 2000 Revised by: mcBugs fixed, plus much additional material and more example February 2001 Revised by: mcAnother major July 2001 Revised by: mcMore bugfixes, much more material, more scripts a complete revision and expansion of the September 2001 Revised by: mcMajor update. Bugfixes, material added, chapters and sections October 2001 Revised by: mcBugfixes, reorganization, material added.

2 Stable January 2002 Revised by: mcBugfixes, material and scripts March 2002 Revised by: mcBugfixes, material and scripts June 2002 Revised by: mc'TANGERINE' release: A few bugfixes, much more material and scripts June 2002 Revised by: mc'MANGO' release: Quite a number of typos fixed, more material and scripts July 2002 Revised by: mc'PAPAYA' release: A few bugfixes, much more material and scripts 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 andlore.

3 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,under the premise that the only way to really learn scripting is to write 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. See the change log for a revision Anita, the source of all the magicTable of ContentsChapter 1. Why Shell Programming?..1 Chapter 2. Starting Off With a Sha Invoking the Preliminary 2.

4 3. Exit and Exit 4. Special 5. Introduction to Variables and Variable Variable bash Variables Are Special Variable 6. 7. Test File test Comparison operators (binary).. Nested if/then Condition Testing Your Knowledge of 8. Operations and Related Numerical 3. Beyond the 9. Variables Internal Manipulating Manipulating strings using Further Parameter Typing variables: declare or Indirect References to $RANDOM: generate random The Double Parentheses 10. Loops and Nested Loop Testing and bash scripting GuideiTable of ContentsChapter 11.

5 Internal Commands and Job Control 12. External Filters, Programs and Basic Complex Time / Date Text Processing File and Archiving Communications Terminal Control Math Miscellaneous 13. System and Administrative 14. Command 15. Arithmetic 16. I/O Using Redirecting Code 17. Here 18. Recess 4. Advanced 19. Regular A Brief Introduction to Regular 20. 21. Restricted 22. Process 23. Complex Functions and Function Local Local variables make recursion 24. 25. List bash scripting GuideiiTable of ContentsChapter 26. 27. 28. /dev and 29.

6 Of Zeros and 30. 31. 32. 33. scripting With Unofficial Shell scripting 34. Interactive and non interactive shells and Shell Tests and Comparisons: "Colorizing" Assorted Security Portability Shell scripting Under 35. bash , version 36. Author's About the Tools Used to Produce This Software and A. Contributed B. A Sed and Awk Micro bash scripting GuideiiiTable of ContentsAppendix C. Exit Codes With Special D. A Detailed Introduction to I/O and I/O E. F. History G. A Sample .bashrc H. Converting DOS Batch Files to Shell I. Analyzing Writing J.

7 bash scripting GuideivChapter 1. Why Shell Programming?A working knowledge of shell scripting is essential to everyone wishing to become reasonably adept atsystem administration, even if they do not anticipate ever having to actually write a script. Consider that as aLinux machine boots up, it executes the shell scripts in / to restore the system configuration andset up services. A detailed understanding of these startup scripts is important for analyzing the behavior of asystem, and possibly modifying shell scripts is not hard to learn, since the scripts can be built in bite sized sections and there is onlya fairly small set of shell specific operators and options [1] to learn.

8 The syntax is simple andstraightforward, similar to that of invoking and chaining together utilities at the command line, and there areonly a few "rules" to learn. Most short scripts work right the first time, and debugging even the longer ones shell script is a "quick and dirty" method of prototyping a complex application. Getting even a limitedsubset of the functionality to work in a shell script, even if slowly, is often a useful first stage in projectdevelopment. This way, the structure of the application can be tested and played with, and the major pitfallsfound before proceeding to the final coding in C, C++, Java, or scripting hearkens back to the classical UNIX philosophy of breaking complex projects into simplersubtasks, of chaining together components and utilities.

9 Many consider this a better, or at least moreesthetically pleasing approach to problem solving than using one of the new generation of high poweredall in one languages, such as Perl, which attempt to be all things to all people, but at the cost of forcing youto alter your thinking processes to fit the not to use shell scripts resource intensive tasks, especially where speed is a factor (sorting, hashing, etc.) procedures involving heavy duty math operations, especially floating point arithmetic, arbitraryprecision calculations, or complex numbers (use C++ or FORTRAN instead) cross platform portability required (use C instead) complex applications, where structured programming is a necessity (need typechecking of variables,function prototypes, etc.)

10 Mission critical applications upon which you are betting the ranch, or the future of the company situations where security is important, where you need to guarantee the integrity of your system andprotect against intrusion, cracking, and vandalism project consists of subcomponents with interlocking dependencies extensive file operations required ( bash is limited to serial file access, and that only in a particularlyclumsy and inefficient line by line fashion) need multi dimensional arrays need data structures, such as linked lists or trees need to generate or manipulate graphics or GUIs need direct access to system hardware need port or socket I/O need to use libraries or interface with legacy code proprietary, closed source applications (shell scripts are necessarily Open Source) If any of the above applies, consider a more powerful scripting language, perhaps Perl, Tcl, Python, orpossibly a high level compiled language such as C, C++, or Java.


Related search queries