@2013/7/19
-Add the bashmap_clear command to delete the key or empty the entire map. Step 1: Add the function to the bash script (or. bashrc)
# for Bashmap {# echo MD5 code for $ MD5 () {if [x "$ = = X"] then echo "" Else echo "| Md5sum-|
Cut-c 1-32 fi} # Usage # > Bashmap "Key" "Value" # set Map[key] = value.
# > Bashmap "key" # Print Map[key] Bashmap () {wx_bashmap_prefix= "BASHMAP_" Export Wx_bashmap_prefix
md5key=$ (eval "MD5") case "$#" in 1) eval "echo \$ $WX _bashmap_prefix$md5key";;
2) eval "Export $WX _bashmap_prefix$md5key= ' $ '";;
* echo ' Usage: ' echo ' bashmap ' key ' ' value ' ' echo ' bashmap ' key '; ESAC} # Usage: # > bashmap_clear # Clear all map items # > Bashmap_c Lear key # clear a map time by Key Bashmap_clear () { wx_bashmap_prefix= "BASHMAP_" export WX_BASHMAP_PR Efix Case "$#" in 0) to Env in $ (set | grep "^ $WX _bashmap_prefix" | cut-d ' = '-f1) & nbsp Do unset $env &nbsP
Done ;;
1) md5key=$ (eval "MD5 '") unset $WX _bashmap_prefix$md5key ;;
ESAC} # for Bashmap}
Step 2: Use Bashmap to set Key:value
> Bashmap a ' value for A '
> Bashmap b ' value for B '
> Bashmap "a B" "value for a B"
Step 3: The utility Bashmap obtains the key corresponding value, if does not have the default key then returns the empty string ""
> Bashmap a
value for a
> Bashmap b
value for b
> bashmap "A B"
value for a B
Step 4: Delete the specified key
> bashmap_clear "B"
Step 5: Empty the map
> Bashmap_clear
Have fun! :)