#!/bin/bash # parameters.sh # Demonstration/sample code of how to require a fixed number of parameters to be passed # If that number ($ARGS) is not met, display help # This example requires 2 arguments ... -t target_volume # -h and -? are offered to the user as the suggested "help" parameters because they are the #. typical UNIX help parameters. In reality, anything except "-t target_volume" will display_help. display_help () { # clear echo echo "Usage:" echo " `basename $0` [ -t target_volume | -h | -? ]" echo echo "Description:" echo " Installs all software packages of the ALCO image to the specified target computer." echo echo "Options:" echo " `basename $0` -t target_volume --> Specify the target_volume for the installations." echo " `basename $0` -h --> Display this help file." echo " `basename $0` -? --> Display this help file." echo exit $ERR_ARGS } # Require this many arguments # arg1 & arg2: -t TARGET_VOLUME # anything else displays help ARGS=2 # Error codes ERR_ARGS=65 ## incorrect number or type of arguments if [[ $# != "$ARGS" ]]; then display_help else # 2 arguments were passed while [ $# -gt 0 ] ; do case "$1" in -t) TARGET_VOLUME="$2" shift ;; *) display_help ;; esac shift done fi if [[ -n "$TARGET_VOLUME" ]]; then echo "TARGET_VOLUME = $TARGET_VOLUME" fi exit 0