#!/bin/bash while [[ $# -gt 0 ]]; do case "$1" in -a|--all) # set option a/all shift # and get the next argument ;; -h|--help) # display help exit # because we want to stop ;; -z|--zooper) zooper=$2 # grab the NEXT argument after the -z|--zooper shift # throw away the -z|--zooper shift # and throw away its value that we've also used ;; -*|--*) echo "We've found an unknown option: $1" # show help if you like shift break # stop parsing but allow script to continue, if that's useful ;; *) echo "I don't know how we got here, it shouldn't happen. Should have handled the args or hit the unknowns option just above." exit ;; esac done