Update formatting
This commit is contained in:
parent
69f50888f4
commit
8ea2be4731
33
bash.md
33
bash.md
|
@ -464,8 +464,9 @@ for i in "${arrayName[@]}"; do
|
||||||
done
|
done
|
||||||
```
|
```
|
||||||
|
|
||||||
Dictionaries (Associative Arrays)
|
Dictionaries
|
||||||
--------------------------------
|
------------
|
||||||
|
{: .-three-column}
|
||||||
|
|
||||||
### Defining
|
### Defining
|
||||||
|
|
||||||
|
@ -480,23 +481,33 @@ sounds[bird]="tweet"
|
||||||
sounds[wolf]="howl"
|
sounds[wolf]="howl"
|
||||||
```
|
```
|
||||||
|
|
||||||
|
Declares `sound` as a Dictionary object (aka associative array).
|
||||||
|
|
||||||
### Working with dictionaries
|
### Working with dictionaries
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
echo ${sounds[dog]} # Dog's sound
|
echo ${sounds[dog]} # Dog's sound
|
||||||
echo ${sounds[@]} # All the values
|
echo ${sounds[@]} # All values
|
||||||
echo ${!sounds[@]} # All the keys
|
echo ${!sounds[@]} # All keys
|
||||||
echo ${#sounds[@]} # Number of elements
|
echo ${#sounds[@]} # Number of elements
|
||||||
unset sounds[dog] # Delete dog
|
unset sounds[dog] # Delete dog
|
||||||
```
|
```
|
||||||
|
|
||||||
### Iteration
|
### Iteration
|
||||||
|
|
||||||
|
#### Iterate over values
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
for i in "${sounds[@]}"; do # Iterate over values
|
for val in "${sounds[@]}"; do
|
||||||
echo $i
|
echo $val
|
||||||
done
|
done
|
||||||
for i in "${!sounds[@]}"; do # Iterate over keys
|
```
|
||||||
echo $i
|
|
||||||
|
#### Iterate over keys
|
||||||
|
|
||||||
|
```bash
|
||||||
|
for key in "${!sounds[@]}"; do
|
||||||
|
echo $key
|
||||||
done
|
done
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue