Chapter 10. Writing Basic Scripts


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, and then execute them any time you wantwithout 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, and then apply it to any directory at any time. You do the hard work one time, and then reuse the script any time you need to.

In this book we'll discuss creating scripts using the sh (Bourne) shell. Scripts can be written with any shelland zsh and bash in particular are quite good for scripting.

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.




Unix(c) Visual Quickstart Guide
UNIX, Third Edition
ISBN: 0321442458
EAN: 2147483647
Year: 2006
Pages: 251

Similar book on Amazon

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