6. Passing Arguments

Shell programs become far more useful after you learn how to process arguments passed to them. In this chapter, you’ll learn how to write shell programs that take arguments typed on the command line. Recall the one-line program run that you wrote in Chapter 4 to run the file sys.caps through tbl, nroff, and lp:

$ cat run tbl sys.caps | nroff -mm –Tlp | lp $

Suppose that you need to run other files besides sys.caps through this same command sequence. You could make a separate version of run for each such file; or, you could modify the run program so that you could specify the name of the file to be run on the command line. That is, you could change run so that you could type

run new.hire

for example, ...

Get Shell Programming in Unix, Linux and OS X, Fourth Edition now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.