Looping your scripts

Suppose you've created a script that you'd like to apply to several files. For example, say that at the end of each day you need to make backup copies of all .html files in your www directory. You could make a backup of each individual .html file, but that's a lot of work. An easier way would be to create a short script to copy an .html file, then loop the script to apply to all .html files in your www directory (Figure 10. 5). You create one short script; UNIX does the tedious work for you.

Figure 10.5. Using a loop with an embedded command, you can automatically apply a script to several files.

To make a loop:

1.
 vi ...

Get Unix: Visual QuickStart Guide 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.