Chapter contents
Creating shell scripts
Running shell scripts
Making scripts executable
Getting a head start on creating scripts
Embedding commands in scripts
Looping scripts
Creating if-then statements
Accepting command line input
Accepting command line input while a script is running
Debugging scripts
So far in this book, you've been typing in commands (or perhaps combining commands), pressing , then waiting for UNIX to execute the command(s) you specified…and typing in commands, pressing , and waiting for UNIX…and typing in commands…. You get the idea, and you probably have tired fingers by now.
Using shell scripts, you can create a series of commands, save them as a single file, then execute them anytime you want—without having to re-create the commands or do all that tedious typing over and over again. For example, suppose you want to do a complex search and replace on all the .htm files in your home directory. With a shell script, you can take the time to structure the commands just one time, save the commands as a single file, then apply it to any directory at any time. Essentially, you do the hard work one time, then can reuse the script any time you need to.
In this book we'll discuss creating scripts using the sh (Bourne) shell.
In this chapter, we'll show you how to get started creating and using shell scripts. We won't go into the gory details about scripting (thank goodness, right?!), but we will give you enough information to create your own scripts and apply them to your particular uses.
18.117.77.54