December 1999
Beginner
528 pages
11h 10m
English
We have already seen how to pass parameters to scripts by using the special variables $1..$9. Using $# can tell us how many parameters have been passed. We also know how to construct a usage statement, which is when we need to inform the user on how to call a script or function with its proper calling parameters.
In this chapter we will cover:
shift;
getopts; and
shift and getopts examples.
To recap, here’s a framework of a script that handles the parameters start and stop. The script requires two parameters. If it does not get two parameters then a usage statement is produced. Notice we use the case statement to process the different parameters coming into the script.
$ pg opt #!/bin/sh # opt usage() ...Read now
Unlock full access