Last active
November 13, 2018 22:43
-
-
Save n1kk/ece1b9ccb325b1d57ca4d1b8874b8665 to your computer and use it in GitHub Desktop.
Helpers to work with key value map storage in bash
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
# 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