Last active
August 29, 2015 14:18
-
-
Save hilotech/f9664a0e77644b479e33 to your computer and use it in GitHub Desktop.
bash(>3) : getopts long options
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Usage: local -A __opts=`_getOptsArray --hoge=fuga --age=uge` | |
# to get the value: ${__opts["hoge"]} | |
function _getOptsArray() { | |
local __name='' | |
local __value='' | |
local __declaration='' | |
local -A __opts | |
for OPT in "$@" | |
do | |
__name=${OPT%%=*} | |
__name=${__name#--} | |
[ -z "$__name" ] && continue | |
__value=${OPT#*=} | |
__declaration="$__declaration[\"$__name\"]=\"$__value\" " | |
done | |
__declaration="( $__declaration)" | |
echo $__declaration | |
} | |
function main() { | |
local -A __opts=`_getOptsArray --hoge=fuga --age=uge` | |
echo ${!__opts[@]} | |
echo ${__opts[@]} | |
} | |
main |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment