The ease of shell programming is one of the real highlights of UNIX for novices. A shell program need be no more than a single complex command line saved in a file - or a series of commands.
For example, let's say that you occasionally need to convert a Macintosh Microsoft Word file for use on your UNIX system. Word lets you save the file in ASCII format. But there's a catch: the Macintosh uses a carriage return ( ) to mark the end of each line, while UNIX uses a linefeed (ASCII 012). As a result, with UNIX, the file looks like one long paragraph, with no end in sight.
tr '\015' '\012' <
tr '\015' '\012'
Make the file executable with:
chmod +x mac2UNIX
Now you can say:
But say, why settle for that? What if you want to convert a bunch of files at once? Easy. The shell includes a general way of referring to arguments passed to a script, and a number of looping constructs. The script:
for x do echo "Converting $x" tr '\015' '\012' < "$x" > "tmp.$x" mv "tmp.$x" "$x" done
will convert any number of files with one command, replacing each original with the converted version:
file1 file2 file3 ...
As you become more familiar with UNIX, it quickly becomes apparent that doing just a little homework can save hours of tedium. This script incorporates only two simple programming constructs: the for loop and . As a new user, with no programming experience, I learned these two constructs by example: I saved a skeleton for loop in a file and simply filled in the blanks with whatever commands I wanted to repeat.
Simple shell programs like this did more for my feeling that computers could automate my work than anything since my first introduction to word processing. It made real sense of the line, "Let the computer do the dirty work."
In short, UNIX is sometimes difficult because it is so rich and complex. The user who doesn't want to learn the complexity doesn't have to - the basic housekeeping commands are as simple as MS-DOS on the IBM PC. But the user who wants to take the time to investigate the possibilities can uncover a wealth of useful tools.