Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bash-bastion/bash-object
Manipulate heterogenous data hierarchies in Bash.
https://github.com/bash-bastion/bash-object
basalt bash shell
Last synced: 15 days ago
JSON representation
Manipulate heterogenous data hierarchies in Bash.
- Host: GitHub
- URL: https://github.com/bash-bastion/bash-object
- Owner: bash-bastion
- License: mpl-2.0
- Created: 2021-08-10T09:58:37.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-10-20T14:20:50.000Z (about 1 year ago)
- Last Synced: 2024-09-07T10:03:17.446Z (4 months ago)
- Topics: basalt, bash, shell
- Language: Shell
- Homepage: https://bash-bastion.github.io/bash-object/
- Size: 2.97 MB
- Stars: 28
- Watchers: 2
- Forks: 0
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# bash-object
Manipulate heterogenous data hierarchies in Bash.
This is meant to be a low level API providing primitives for other libraries.
## Exhibition
```sh
# Problem: How to represent the following in Bash?# {
# "zulu": {
# "yankee": {
# "xray": {
# "whiskey": "victor",
# "foxtrot": ["omicron", "pi", "rho", "sigma"]
# }
# }
# }
# }# Solution: Use bash-object to construct the hierarchy
declare -A root_object=()
declare -A zulu_object=()
declare -A yankee_object=()
declare -A xray_object=([whiskey]=victor)
declare -a foxtrot_array=(omicron pi rho sigma)bobject set-object --ref root_object '.zulu' zulu_object
bobject set-object --ref root_object '.zulu.yankee' yankee_object
bobject set-object --ref root_object '.zulu.yankee.xray' xray_object
bobject set-array --ref root_object '.zulu.yankee.xray.foxtrot' foxtrot_arraybobject get-object --value root_object '.zulu.yankee.xray'
assert [ "${REPLY[whiskey]}" = victor ]bobject get-string --value root_object '.zulu.yankee.xray.whiskey'
assert [ "$REPLY" = victor ]bobject get-array --value root_object '.zulu.yankee.xray.foxtrot'
assert [ ${#REPLY[@]} -eq 4 ]bobject get-string --value root_object '.["zulu"].["yankee"].["xray"].["foxtrot"].[2]'
assert [ "$REPLY" = rho ]bobject.print 'root_object'
# |__ zulu (__bash_object_root_object___zulu_24092_8313_29963_14301_14535)
# |__ yankee (__bash_object_root_object___zulu_yankee_15383_14163_12814_23488_13779)
# |__ xray (__bash_object_root_object___zulu_yankee_xray_18071_28791_7790_539_19231)
# |__ whiskey
# |__ foxtrot (__bash_object_root_object___zulu_yankee_xray_foxtrot_26606_15833_10655_7208_16587)
# |- omicron
# |- pi
# |- rho
# |- sigma
```## Installation
Use [Basalt](https://github.com/hyperupcall/basalt), a Bash package manager, to add this project as a dependency
```sh
basalt add hyperupcall/bash-object
```