Correct Number of Parameters

/ Published in: Bash
Save to your folder(s)

Tests whether the script has been invoked with the correct number of parameters.

Copy this code and paste it in your HTML
  1. E_WRONG_ARGS=85
  2. script_parameters="-a -h -m -z"
  3. # -a = all, -h = help, etc.
  4. if [ $# -ne $Number_of_expected_args ]
  5. then
  6. echo "Usage: `basename $0` $script_parameters"
  7. # `basename $0` is the script's filename.
  8. exit $E_WRONG_ARGS
  9. fi

Report this snippet


RSS Icon Subscribe to comments

You need to login to post a comment.