32POSITIONAL PARAMETERS

image

One feature that has been missing from our programs so far is the ability to accept and process command line options and arguments. In this chapter, we will examine the shell features that allow our programs to get access to the contents of the command line.

Accessing the Command Line

The shell provides a set of variables called positional parameters that contain the individual words on the command line. The variables are named 0 through 9. They can be demonstrated this way:

#!/bin/bash# posit-param: script to view command line parametersecho "\$0 = $0\$1 = $1\$2 = $2\$3 = $3\$4 = $4\$5 = $5\$6 = $6\$7 = $7\$8 = $8\$9 = ...

Get The Linux Command Line, 2nd Edition now with O’Reilly online learning.

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