Skip to content

Instantly share code, notes, and snippets.

@n1kk
Last active November 13, 2018 22:43
Show Gist options
  • Save n1kk/ece1b9ccb325b1d57ca4d1b8874b8665 to your computer and use it in GitHub Desktop.
Save n1kk/ece1b9ccb325b1d57ca4d1b8874b8665 to your computer and use it in GitHub Desktop.
Helpers to work with key value map storage in bash
# map helpers
hput() {
eval "$1""$2"='$3';
}
hget() {
eval echo '${'"$1$2"'#hash}';
}
# bulk set
hset() {
local map=$1; shift;
while [ ! $# -eq 0 ]; do { hput $map $1 $2; shift 2; } done
}
hset map key1 value1
echo `hget map key1` # value1
hset map2 key1 val1 key2 val2
echo `hget map2 key1` # val1
echo `hget map2 key2` # val2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment