#!/bin/bash provided_options= do_has_option() { echo "$1" | grep -q -- "\(^\| \)$2\(\$\| \)" } has_option() { do_has_option "$provided_options" "$1" } while true do case $1 in -*) if do_has_option "$allowed_options" "$1" then provided_options+=" $1" else echo "Unknown option: $1" usage fi shift ;; *) break ;; esac done