Chapter 9. Learn Shell Scripting


This chapter covers many aspects of shell scripting. In keeping with the spirit of the book, it's not an A-to-Z tutorial on the subject. Rather, each project tackles a particular technology pertinent to writing shell scripts. The 13 projects cover the following topics:

Bash functions in a script, parameter expansion, here-documents, and script debugging

Regular expressions, both modern (extended) and obsolete (basic)

Shell quoting

Forming conditions for use in conditional expressions

Subshells and command blocks

Traps and handles, and how to implement them in a shell script

If you are not familiar with writing shell scripts, read Projects 9 and 10 for an introduction. See Project 4 for a discussion of shell and environment variables and how they differ in scope. Project 52 covers Bash functions.

The chapter focuses on scripting with Bash, the default shell for accounts created in Mac OS X. If your chosen interactive shell is not Bash, don't worry; you can still write and use the scripts you'll find here. Just make Bash execute them by making the first line of each script read #!/bin/bash. See Project 5 for a comparison of shells.

The projects in this chapter are fairly advanced. It's not a tutorial on writing shell scripts; rather, it presents useful and practical solutions to some of the most common scripting tasks. It's of most use to those who have grasped the basics of scripting and want to start writing real-world scripts.




Mac OS X UNIX 101 Byte-Sized Projects
Mac OS X Unix 101 Byte-Sized Projects
ISBN: 0321374118
EAN: 2147483647
Year: 2003
Pages: 153
Authors: Adrian Mayo

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net