Chapter 9. Creating and Using Scripts


A script is simply a text file that contains a series of commands. By definition, a script must be read and executed by a program called an interpreter , a separate program that understands the commands in the script.

You may already be familiar with scripts written in AppleScript or JavaScript. In the Unix world, we often speak of shell scripts scripts that are written to be interpreted by one of the Unix shells , such as sh , bash , and tcsh . These scripts use exactly the same commands that you would type at the command line using the corresponding shell. Indeed, one of the reasons for using a script is to reduce the chance of mistyping a complicated command line. So when you see the term Bourne shell script , you know it's referring to a script that is written to be interpreted by the Bourne shell ( /bin/sh ). See man sh for the online manual for the Bourne shell.

Think of a shell script as a small computer program. The languages available for writing shell scripts are numerous , but by far the most commonly used is the Bourne shell. This is because the Bourne shell has been around so long, it has become the de facto standard for programming system-configuration files and for system administration. A script written for the Bourne shell is likely to run properly on the widest variety of Unix systems. So in this chapter we will show you the basics of Bourne shell scripts.

In Chapter 2, "Using the Command Line," you created a simple shell script. Now you will delve more deeply into scripting, learning the basic tools through which all shell scripts are made: commands, operators, variables , conditionals, loops , and functions. Sound like computer programming? It is, but don't worryyou don't have to become a programmer to benefit from understanding and using scripts, and if you do want to get further into programming, then shell scripts are a good place to start.



Unix for Mac OS X 10. 4 Tiger. Visual QuickPro Guide
Unix for Mac OS X 10.4 Tiger: Visual QuickPro Guide (2nd Edition)
ISBN: 0321246683
EAN: 2147483647
Year: 2004
Pages: 161
Authors: Matisse Enzer

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