Skip to Content
Unix Power Tools, 3rd Edition
book

Unix Power Tools, 3rd Edition

by Jerry Peek, Shelley Powers, Tim O'Reilly, Mike Loukides
October 2002
Intermediate to advanced content levelIntermediate to advanced
1154 pages
49h 36m
English
O'Reilly Media, Inc.
Content preview from Unix Power Tools, 3rd Edition

Chapter 36. Shell Programming for the Initiated

Beyond the Basics

This chapter has a bunch of tricks and techniques for programming with the Bourne shell. Some of them are documented but hard to find; others aren’t documented at all. Here is a summary of this chapter’s articles:

  • The first group of articles is about making a file directly executable with #! on the first line. On many versions of Unix, an executable file can start with a first line like this:

    #!/path/to/interpreter

    The kernel will start the program named in that line and give it the file to read. Chris Torek’s Usenet classic, Section 36.2, explains how #! started. Section 36.3 explains that your “shell scripts” may not need a shell at all.

  • The next bunch of articles are about processes and commands. The exec command, Section 36.5, replaces the shell with another process; it can also be used to change input/output redirection (see below). The : (colon) operator evaluates its arguments and returns a zero status — Section 36.6 explains why you should care.

  • Next are techniques for handling variables and parameters. Parameter substitution, explained in Section 36.7, is a compact way to test, set, and give default values for variables. You can use the $0 parameter and Unix links to give the same script multiple names and make it do multiple things; see Section 36.8. Section 36.9 shows the easy way to get the last command-line argument. Section 36.10 has an easy way to remove all the command-line arguments.

  • Four articles cover ...

Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

UNIX and Linux System Administration Handbook, 5th Edition

UNIX and Linux System Administration Handbook, 5th Edition

Trent R. Hein, Evi Nemeth, Garth Snyder, Ben Whaley, Dan Mackin

Publisher Resources

ISBN: 0596003307Supplemental ContentErrata Page