Created
March 22, 2015 08:30
-
-
Save tomschr/59126140d7eca4c006ab to your computer and use it in GitHub Desktop.
Parse Parameter-Value Pair into Global Shell Array
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
# Declare our array | |
declare -A PARAMS | |
function parse_param() { | |
# Syntax: parse_param "PARAMETER=VALUE" | |
# Extract parameter and value and store it in Shell array" | |
local _PARAM=$1 | |
[[ "$_PARAM" == *"="* ]] || exit_on_error "Option -p must have the syntax PARAMETER=VALUE" | |
p=${_PARAM%=*} | |
v=${_PARAM#*=} | |
# Define associative array: | |
PARAMS["$p"]="$v" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment