Skip to content

Commit aed7b9d

Browse files
committed
docs: Polish and improvements
1 parent e888ff5 commit aed7b9d

File tree

1 file changed

+8
-12
lines changed

1 file changed

+8
-12
lines changed

Diff for: docs/getting-started-technical.md renamed to docs/motivation.md

+8-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
1-
# Unmarshaling
1+
# Motivation
22

3-
Unmarshaling strings representing highly structured data in Bash in a reliable and easy to use way has historically been impossible - until now
3+
Unmarshaling strings representing highly structured data in Bash in a reliable and easy to use way has historically been impossible
44

5-
The following examples will use JSON format, which represents the data that Bash will encode in-memory
6-
7-
## Motivation
8-
9-
Bash allows for simple/flat mapping via an associative array
5+
Bash only allows for simple/flat mapping via an associative array
106

117
```json
128
{
@@ -59,8 +55,8 @@ Let's take a look at the most basic case
5955
In Bash, it will be stored in memory eventually using declarations similar to the following
6056

6157
```sh
62-
declare -A unique_global_variable_xray=([yankee]='zulu')
63-
declare -A OBJECT=([xray]=$'\x1C\x1Dtype=object;&unique_global_variable_xray')
58+
declare -A __bash_object_unique_global_variable_xray=([yankee]='zulu')
59+
declare -A OBJECT=([xray]=$'\x1C\x1Dtype=object;&__bash_object_unique_global_variable_xray')
6460
```
6561

6662
You can retrieve the data with
@@ -73,7 +69,7 @@ assert [ "${REPLY[yankee]}" = zulu ]
7369
The implementation hinges on Bash's `declare -n`. When using `get-object`, this is what would happen behind the scenes at the lowest level
7470

7571
```sh
76-
local current_object_name='unique_global_variable_xray'
72+
local current_object_name='__bash_object_unique_global_variable_xray'
7773
local -n current_object="$current_object_name"
7874

7975
declare -gA REPLY=()
@@ -83,7 +79,7 @@ for key in "${!current_object[@]}"; do
8379
done
8480
```
8581

86-
Another implementation detail is how a new variable is created in the global scope. This can occur when you are setting an array (indexed array) or object (associative array) at some place in the object hierarchy. In the previous example, `unique_global_variable_xray` is the new variable created in the global scope; in practice, the name looks a lot different, as seen in the example below
82+
Another implementation detail is how a new variable is created in the global scope. This can occur when you are setting an array (indexed array) or object (associative array) at some place in the object hierarchy. In the previous example, `__bash_object_unique_global_variable_xray` is the new variable created in the global scope; in practice, the name looks a lot different, as seen in the example below
8783

8884
```sh
8985
local global_object_name=
@@ -97,4 +93,4 @@ local -n global_object="$global_object_name"
9793
global_object=()
9894
```
9995

100-
The `%q` probably isn't needed (it was originally there because the implementation previously used `eval`), but it's still there as of this writting
96+
The `%q` probably isn't needed (it was originally there because the implementation previously used `eval`), but it's still there as of this writing

0 commit comments

Comments
 (0)