A simple map implementation in bash
Create a new map with the given name and key-value pairs.
- map::make
- map::get
- map::set
- map::print
- map::delete
- map::clear
- map::exists
- map::size
- map::values
- map::keys
- map::has
- map::usage
Create a new map with the given name and key-value pairs.
map::make my_map "[name]=John Doe
[age]=30
[city]=New York"
- $1 (string): The name of the map to create
- $2 (string): A multi-line string of key-value pairs
- 0: If successful.
- 1: If an error occurs during map creation.
Retrieve the value associated with a key in the specified map.
map::get my_map name
- $1 (string): The name of the map
- $2 (string): The key to retrieve
- 0: If the key is found.
- 1: If the key is not found.
- The value associated with the key if found.
- Error message if the key is not found.
Set or update a key-value pair in the specified map.
map::set my_map job "Software Engineer"
- $1 (string): The name of the map
- $2 (string): The key to set or update
- $3 (string): The value to associate with the key
- 0: If successful.
Print all key-value pairs in the specified map.
map::print my_map
- $1 (string): The name of the map
- 0: If successful.
- All key-value pairs in the map, one per line. Outputs "(empty)" if the map is empty.
Delete a key-value pair from the specified map.
map::delete my_map age
- $1 (string): The name of the map
- $2 (string): The key to delete
- 0: If successful.
Clear all key-value pairs from the specified map.
map::clear my_map
- $1 (string): The name of the map
- 0: If successful.
Check if a map exists.
map::exists my_map
- $1 (string): The name of the map
- 0: If successful.
- "true" if the map exists, "false" otherwise.
Get the number of key-value pairs in the specified map.
map::size my_map
- $1 (string): The name of the map
- 0: If successful.
- The number of key-value pairs in the map.
Get all values from the specified map.
map::values my_map
- $1 (string): The name of the map
- 0: If successful.
- All values in the map, one per line.
Get all keys from the specified map.
map::keys my_map
- $1 (string): The name of the map
- 0: If successful.
- All keys in the map, one per line.
Check if a key exists in the specified map.
map::has my_map city
- $1 (string): The name of the map
- $2 (string): The key to check
- 0: If the key exists.
- 1: If the key does not exist.
- "true" if the key exists, "false" otherwise.
Display usage information for the map functions.
map::usage
- 0: Always exits with 0.
- Prints usage information, including available functions and examples.