Skip to content

Instantly share code, notes, and snippets.

@tomschr
Created March 22, 2015 08:30
Show Gist options
  • Save tomschr/59126140d7eca4c006ab to your computer and use it in GitHub Desktop.
Save tomschr/59126140d7eca4c006ab to your computer and use it in GitHub Desktop.
Parse Parameter-Value Pair into Global Shell Array
# 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