Advertisement
justin_hanekom

Bash function to display usage and exit

Mar 16th, 2019
231
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 0.91 KB | None | 0 0
  1. ################################################################################
  2. # Function:     usage_exit
  3. # Description:  Prints the usage message for this script and then exits
  4. # Arguments:    $1 :- Exit code; defaults to 1
  5. # Outputs:      Prints description of how to call this script
  6. function usage_exit {
  7.     local exit_code=1
  8.  
  9.     if [[ ${1-} =~ ^[0-9]+$ ]]; then
  10.         exit_code="$1"
  11.     fi
  12.  
  13.     cat << EOT
  14. Usage: $(basename "$0") [options]...
  15.     -u|--user       <val>   (Required) The owner of the generated file
  16.     -d|--destdir    <val>   (Required) The dir into which to save the new file
  17.     -r|--remove             Causes previous files to be removed
  18.     -v|--verbose            Displays verbose output
  19.     -h|--help               Displays this message and aborts the script
  20.  
  21. NOTE: The <user> and <destdir> arguments are mandatory and *must* be supplied
  22.  
  23. EOT
  24.     exit "${exit_code}"
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement