| 1 | #!/bin/bash |
| 2 | |
| 3 | ARGS=1 # Number of arguments expected. |
| 4 | E_BADARGS=85 # Exit value if incorrect number of args passed. |
| 5 | |
| 6 | test $# -ne $ARGS && \ |
| 7 | # ^^^^^^^^^^^^ condition #1 |
| 8 | echo "Usage: `basename $0` $ARGS argument(s)" && exit $E_BADARGS |
| 9 | # ^^ |
| 10 | # If condition #1 tests true (wrong number of args passed to script), |
| 11 | #+ then the rest of the line executes, and script terminates. |
| 12 | |
| 13 | # Line below executes only if the above test fails. |
| 14 | echo "Correct number of arguments passed to this script." |
| 15 | |
| 16 | exit 0 |
| 17 | |
| 18 | # To check exit value, do a "echo $?" after script termination. |