44. Shell Programming for the UninitiatedContents:
44.1 Everyone Should Learn Some Shell ProgrammingOne of the great things about UNIX is that it's made up of individual utilities, "building blocks" like cat and grep , that you run from a shell prompt. Using pipes, redirection, filters, and so on, you can combine those utilities to do an incredible number of things. Shell programming lets you take the same commands you'd type at a shell prompt - and put them into a file you can run by just typing its name. You can make new programs that combine UNIX programs (and other shell scripts) in your own way to do exactly what you need. If you don't like the way a program works, you can write a shell script to do just what you want. Because many UNIX users use the shell every day, they don't need to learn a whole new language for programming... just some tips and techniques. In fact, this chapter covers a lot of programming techniques that you'll want to use even when you aren't programming. For example, loops and tests are handy on the command line. (This series of articles does assume that you've written programs in some language before, or are generally familiar with programming concepts. If you haven't, you might start with a more comprehensive shell programming book.) Some of the topics you need to learn about as a beginning shell programmer have already been covered in other chapters. Here are the articles you'll probably want to read - in an order that makes sense if you're looking for something of a tutorial:
This chapter discusses only Bourne shell programming. In most cases, the C shell isn't great for shell programming (47.2 ) .
A note about command versions:
unfortunately, the same commands on different versions of UNIX can
have different options.
Some Bourne shells are a little different from others.
For instance, some
test
(44.20
)
commands have a -x
option to test for an
executable file; others don't.
As article
46.10
explains,
some echo
commands use a -n
option to mean "no newline at the
end of this string"; others have you put - |
|