Programming

We mention earlier that the shell is the system’s command interpreter. It reads each command line you enter at your terminal and performs the operation that you call for. Your shell is chosen when your account is set up.

The shell is just an ordinary program that can be called by a Unix command. However, it contains some features (such as variables, control structures, and so on) that make it similar to a programming language. You can save a series of shell commands in a file, called a shell script, to accomplish specialized functions.

Programming the shell should be attempted only when you are reasonably confident in your ability to use Unix commands. Unix is quite a powerful tool, and its capabilities become more apparent when you try your hand at shell programming.

Take time to learn the basics. Then, when you’re faced with a new task, take time to browse through references to find programs or options that will help you get the job done more easily. Once you’ve done that, learn how to build shell scripts so that you never have to type a complicated command sequence more than once.

Let’s have a closer look at a shell script to give you some flavor of what can be done. First, to list all known user accounts on the system, you need to extract the information from the NetInfo database, which can be done by using nireport.

Tip

You can try this script, listusers, by entering the following few lines into vi, pico, or another editor of your choice. See Chapter 4 for additional ...

Get Learning Unix for Mac OS X Panther now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.