#!/bin/bash # Search the given arguments for the value of the specified key # $1 - the name of the argument - (e.g. "verbose") # $2+ - arguments to parse for value - (e.g. some args --verbose=3 more args) function args_get_long { local want_key=$1; shift; while [[ $# -gt 0 ]] do local key="$1" case $key in "--$want_key") echo $2 return ;; --$want_key=*) echo "${key#*=}" return ;; esac shift done } # Search the given arguments for the value of the specified key # $1 - the name of the argument's short form - (e.g. "v") # $2+ - arguments to parse for value - (e.g. some args -v=3 more args) function args_get_short { local want_key=$1; shift; while [[ $# -gt 0 ]] do local key="$1" case $key in "-$want_key") echo $2 return ;; -$want_key=*) echo "${key#*=}" return ;; esac shift done } # Search the given arguments for the value of the specified key or short # $1 - the long name of the argument - (e.g. "verbose") # $2 - the short name of the argument - (e.g. "v") # $3+ - arguments to parse for value - (e.g. some args -w shorts --and longs more args) function args_get { local want_long=$1; shift; local want_short=$1; shift; while [[ $# -gt 0 ]] do local key="$1" case $key in "--$want_long"|"-$want_short") echo $2 return ;; --$want_long=*|-$want_short=*) echo "${key#*=}" return ;; esac shift done }