Example: stock market

Advanced Bash-Scripting Guide - UNAM

Advanced bash scripting GuideAn in depth exploration of the art of shell scriptingMendel June 2006 Revision HistoryRevision Feb 2006 Revised by: mc'BLAEBERRY' release: Minor May 2006 Revised by: mc'SPICEBERRY' release: Minor May 2006 Revised by: mc'WINTERBERRY' release: Major 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. 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 book is suitable for classroom use as a general introduction to programming 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

Advanced Bash−Scripting Guide An in−depth exploration of the art of shell scripting Mendel Cooper <thegrendel@theriver.com> 4.0 18 June 2006 Revision History

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 - UNAM

1 Advanced bash scripting GuideAn in depth exploration of the art of shell scriptingMendel June 2006 Revision HistoryRevision Feb 2006 Revised by: mc'BLAEBERRY' release: Minor May 2006 Revised by: mc'SPICEBERRY' release: Minor May 2006 Revised by: mc'WINTERBERRY' release: Major 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. 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 book is suitable for classroom use as a general introduction to programming 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.

2 A pdf version is also available. See thechange 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. 3. Special 4. Introduction to Variables and Variable Variable bash Variables Are Special Variable 5. Quoting 6. Exit and Exit 7. Test File test Other Comparison 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 bash scripting GuideiTable of ContentsChapter 10.

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

4 List 26. 27. /dev and 28. Of Zeros and 29. 30. 31. 32. scripting With Unofficial Shell scripting 33. Interactive and non interactive shells and Shell Tests and Comparisons: "Colorizing" Assorted Security Infected Shell Hiding Shell Script Portability Shell scripting Under 34. bash , versions 2 and bash , bash , version bash scripting GuideiiiTable of ContentsChapter 34. bash , versions 2 and bash , version 35. Author's About the Where to Go For Tools Used to Produce This Software and A. Contributed B. Reference C. A Sed and Awk Micro D. Exit Codes With Special E. A Detailed Introduction to I/O and I/O F.

5 Command Line Standard Command Line bash Command Line G. Important H. Important System I. J. History K. A L. Converting DOS Batch Files to Shell M. Analyzing Writing bash scripting GuideivTable of ContentsAppendix N. Revision O. Mirror P. To Do Q. bash scripting GuidevChapter 1. Why Shell Programming?No programming language is perfect. There is noteven a single best language; there are only languageswell suited or perhaps poorly suited for MayerA working knowledge of shell scripting is essential to anyone wishing to become reasonably proficient atsystem administration, even if they do not anticipate ever having to actually write a script.

6 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 only afairly small set of shell specific operators and options [1] to learn. The syntax is simple and straightforward,similar to that of invoking and chaining together utilities at the command line, and there are only a few "rules"to learn. Most short scripts work right the first time, and debugging even the longer ones is shell script is a "quick and dirty" method of prototyping a complex application.

7 Getting even a limitedsubset of the functionality to work in a shell script is often a useful first stage in project development. Thisway, the structure of the application can be tested and played with, and the major pitfalls found beforeproceeding to the final coding in C, C++, Java, or scripting hearkens back to the classic UNIX philosophy of breaking complex projects into simplersubtasks, of chaining together components and utilities. 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 scriptsResource intensive tasks, especially where speed is a factor (sorting, hashing, etc.)

8 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 or Java instead) Complex applications, where structured programming is a necessity (need type checking of variables,function prototypes, etc.) 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)

9 Need native support for 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 Chapter 1. Why Shell Programming?1 Proprietary, closed source applications (shell scripts put the source code right out in the open for allthe world to see) If any of the above applies, consider a more powerful scripting language perhaps Perl, Tcl, Python, Ruby or possibly a high level compiled language such as C, C++, or Java. Even then, prototyping theapplication as a shell script might still be a useful development will be using bash , an acronym for "Bourne Again shell" and a pun on Stephen Bourne's now classicBourne shell.

10 bash has become a de facto standard for shell scripting on all flavors of UNIX. Most of theprinciples this book covers apply equally well to scripting with other shells, such as the Korn Shell, fromwhich bash derives some of its features, [2] and the C Shell and its variants. (Note that C Shell programmingis not recommended due to certain inherent problems, as pointed out in an October, 1993 Usenet post by TomChristiansen.)What follows is a tutorial on shell scripting . It relies heavily on examples to illustrate various features of theshell. The example scripts work they've been tested, insofar as was possible and some of them are evenuseful in real life. The reader can play with the actual working code of the examples in the source archive( or ), [3] give them execute permission (chmod u+rxscriptname), then run them to see what happens.


Related search queries