title: BASH script : usage displays even if you provide a switch without argument
body: <p>i've tried many ways to do this and I'm stumped. When i try the <code>sudo admpanel -a</code> without argument the script displays the message from the usage() method instead of the error msg i've built into it. But on the other hand if i <code>sudo admpanel -a FirstName</code> it displays me the error msg portion. If i enter <code>sudo admpanel -a FirstName LastName</code> it functions the way its supposed to. Below is the script :</p>
  
  <pre><code>#!/bin/bash
  
  # PROGRAM NAME : admpanel.sh
  
  PROGNAME=${0##*/}
  VERSION="1.0"
  SCRIPT_SHELL=${SHELL}
  
  usage() {
    echo "Usage: ${PROGNAME} [-h|--help ] [-a|--add] [-r|--remove] [-d|--display] [-c|--check] [argument_1] [argument_2]"
  }
  
  help_message() {
      cat &lt;&lt;- _EOF_
      ${PROGNAME} ${VERSION}
      Add/Remove/Display user(s) on Admin Panel. Please note that the password is hardcoded.
      Please consult with the system administrator if you already don't know it.
  
      $(usage)
  
      Options:
  
      -h, --help      Displays help.
      -a, --add       Add user
      -r, --remove    Remove user
      -d, --display   Display all users
      -c, --check     Check specific user
  
      Example:
  
      ${PROGNAME} -a firstName lastName
      ${PROGNAME} --add firstName lastName
  
      ${PROGNAME} -r firstName lastName
      ${PROGNAME} --remove firstName lastName
  
      ${PROGNAME} -d
      ${PROGNAME} -display
  
      ${PROGNAME} -c firstName LastName
      ${PROGNAME} --check firstName LastName
  
  _EOF_
  }
  
  verify() {
      echo "Are you sure you want to do this?"
      read answer
  }
  
  add_employee() {
      echo adding user
  }
  
  remove_employee() {
      echo removing user
  }
  
  display_users() {
      echo displaying users
  }
  
  check_user() {
      echo checking users
  }
  
  
  if [ "$#" -le 1 ]; then
      usage
      exit 1
  elif [[ $USER != "root" ]]; then
      echo "This script must be run as root!"
      exit 1
  elif [[ ($1 == "-h" ) || ($1 == "-help") || ($1 == "--help") ]]; then
      help_message
      exit 0
  elif [[ ($1 == "-a") || ($1 == "-add") || ($1 == "--add") ]]; then
      if [[ -z "$3" ]]; then
          echo "ERROR: First name and last name wasn't provided"
          echo "usage: ${PROGNAME} -a FirstName LastName" 
          exit 1  
      elif [[ (-z "$2") || (-z "$3") ]]; then
          echo "ERROR: Either first name or last name wasn't provided or both"
          echo "usage: ${PROGNAME} -a FirstName LastName"
          exit 1
      else
          read -p "Are you sure you want to continue? &lt;y/N&gt; " prompt
          if [[ $prompt == "y" || $prompt == "Y" || $prompt == "yes" || $prompt == "Yes" ]]; then
              add_employee
              exit 0
          else
              exit 0
          fi
      fi
  elif [[ ($1 == "-r") || ($1 == "-remove") || ($1 == "--remove") ]]; then
      remove_employee
      exit 0
  elif [[ ($1 == "-d") || ($1 == "-display") || ($1 == "--display") ]]; then
      display_users
      exit 0
  elif [[ ($1 == "-c") || ($1 == "-check") || ($1 == "--check") ]]; then
      check_user
      exit 0
  else
      echo something went wrong try again...
      exit 1
  fi
  </code></pre>
  
  <p>please advise. -Thanks in advance.</p>