part of shnell – a source to source compiler enhancement tool
© Jens Gustedt, 2017
A simple hash table for shell programming
The shell has no builtin hash function that would be easy to use. Here, we provide some simple minded approach to close that gap. It has the important restriction that the hashed values must not contain special characters.
Coding and configuration
The following code is needed to enable the sh-module framework.SRC="$_" . "${0%%/${0##*/}}/import.sh"
Imports
The following sh
-modules are imported:
Details
The implementation uses naming conventions and the shell’s eval
feature. All of this is relatively fragile. The name of the hash must be alphanumeric ASCII. The key value can be any string.
Declared functions
hexify
: Transform a string into hexvalues prefixed with “U”
This is then used as unique name component for the shell identifier that emulates the hash entry.
hashout
: Store the value of key $3 of hash $2 in variable $1 value $4 is the default if that entry does not exist
hashin
: Store value $3 into key $2 of hash $1
hashEcho
: Echo the value of key $2 of hash $1. value $3 is the default if that entry does not exist
hashadd
: Add value $3 to the list of key $2 of hash $1
This collects data in a hash position as a ;-separated list