SYNOPSIS
- hashSet
- Aq Value Aq Key Aq HashName [SubHashName [...] ]
- Ft $retval hashGet
- Aq Key Aq HashName [SubHashName [...] ]
- Ft $retval hashKeys
- Aq HashName [SubHashName [...] ]
- hashRemove
- Aq Key Aq HashName [SubHashName [...] ]
- hashDelete
- Aq HashName [SubHashName [...] ]
DESCRIPTION
General
is a collection of functions that implement basic hash data-structure in bash scripting language.The function list:
- hashSet
- Adds a value to the hash
- hashGet
- Returns a value from the hash
- hashKeys
- Returns a list of keys of the hash
- hashRemove
- Removes a key from the hash
- hashDelete
- Deletes a hash
Detailed interface description follows.
FUNCTIONS DESCRIPTIONS
hashSet Ao Fa Value Ac Ao Fa Key Ac Ao Fa Hashname Ac [SubHashName [...] ]
Adds a value to the hash.Parameters:
- Aq Fa Value The value to set in
- Fa HashName Ns Bo Fa Key Bc .
- Aq Fa Key The key for the value
- Fa Value .
- Ao Fa HashName Ac [SubHashName [...] ]
- A string that contains the name of the hash. If the hash is a sub hash of another hash, the "father hash" name MUST BE WRITTEN FIRST, followed by the sub-hash name.
Fa Value will be the value of the key Fa Key in the hash Fa HashName . For example if you have (or want to define) hash C which is subhash of hash B which is subhash of hash A and C has a key named ckey1 with value cval1 then you should use:
Ft $retval hashGet Ao Fa Key Ac Ao Fa HashName Ac [SubHashName [...] ]
Returns the value of Fa Key in Fa HashName to the Ft $retval variable.Parameters:
- Aq Fa Key The key that hold the value we wish to get.
- Ao Fa HashName Ac [SubHashName [...] ]
- A string that contains the name of the hash. If the hash is a sub hash of another hash, the Qq father hash name MUST BE WRITTEN FIRST, followed by the sub-hash name.
Return Value: The value of the key Fa Key in the hash Fa HashName . The value is returned in the variable Ft $retval .
Ft $retval hashKeys Ao Fa HashName Ac [SubHashName [...] ]
Returns a list of keys of the hash Fa HashName in the variable Ft $retval .Parameters:
- Ao Fa HashName Ac [SubHashName [...] ]
- A string that contains the name of the hash. If the hash is a sub hash of another hash, the Qq father hash name MUST BE WRITTEN FIRST, followed by the sub-hash name.
Return Value: The value of the key Fa Key in the hash Fa HashName . The value is returned in the variable Ft $retval .
hashRemove Ao Fa Key Ac Ao Fa HashName Ac [SubHashName [...] ]
Removes the key Fa Key from the hash Fa HashName .- Aq Fa Key The key we wish to remove from
- Fa HashName .
- Ao Fa HashName Ac [SubHashName [...] ]
- A string that contains the name of the hash. If the hash is a sub hash of another hash, the Qq father hash name MUST BE WRITTEN FIRST, followed by the sub-hash name.
This function should also be used to remove a sub-hash from its Qq father hash . In that case, the Fa key will be the name of the sub-hash.
hashDelete Ao Fa HashName Ac [SubHashName [...] ]
Deletes the hash Fa HashName Op SubHashName Op ... .Parameters:
- Ao Fa HashName Ac [SubHashName [...] ]
- A string that contains the name of the hash. If the hash is a sub hash of another hash, the Qq father hash name MUST BE WRITTEN FIRST, followed by the sub-hash name.
If this function is used on a sub-hash, a key with the name of the sub-hash will remain in its Qq father hash and will hold a NULL value.
BUGS
A hash name can only contain characters that are valid as part of bash variable names (i.e. a-zA-Z0-9_). The same applies for hash keys.
As for now, there is no way of knowing if a key represents a value or a sub-hash. If a sub-hash will be used as a key, the returned value will be its keys list.
EXAMPLES
Define hash table hashA with key Akey1 with value Aval1 use:% hashSet Aval1 Akey1 AhashNow:
% hashGet Akey1 Ahash
% echo $retval
Aval1
% hashKeys Ahash
% echo $retval
Akey1
%
HISTORY
The idea to write library appeared when we've discovered the full power of the bash eval function.As of the name , it has two meanings. The first, it means `stash' of hash functions. The second is, that contains subhashes inside, so it looks like stash of packed information.