O'Reilly logo

Shell Programming in Unix, Linux and OS X, Fourth Edition by Patrick Wood, Stephen G. Kochan

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required