fork download
  1. #!/usr/bin/env bash
  2. FOO="SYSCFG_lan_ifname='br1' SYSCFG_lan_ipaddr='10.0.0.1' SYSCFG_lan_netmask='255.255.255.0'"
  3.  
  4. case $BASH_VERSION in
  5. ''|[1-3].*) echo "ERROR: Bash 4.0+ required" >&2; exit 1;;
  6. esac
  7.  
  8. declare -A kwargs=( )
  9. while IFS= read -r -d ''; do
  10. [[ $REPLY = *=* ]] || {
  11. printf 'ERROR: Item %q is not in assignment form\n' "$REPLY" >&2
  12. continue
  13. }
  14. kwargs[${REPLY%%=*}]=${REPLY#*=}
  15. done < <(xargs printf '%s\0' <<<"$FOO")
  16.  
  17. # show what we parsed for demonstration purposes
  18. declare -p kwargs >&2
Success #stdin #stdout #stderr 0.01s 5340KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
declare -A kwargs=([SYSCFG_lan_ifname]="br1" [SYSCFG_lan_netmask]="255.255.255.0" [SYSCFG_lan_ipaddr]="10.0.0.1" )