Fix code highlighting

This commit is contained in:
Digital Studium
2023-07-23 15:55:12 +03:00
parent 7a3d0fc7bd
commit cdac09052a
19 changed files with 146 additions and 58 deletions

View File

@@ -10,19 +10,19 @@ Sometimes there is a need to use in BASH such structures as lists (also known as
Array creation in bash can be done this way:
```shell
```bash
sample_array=(foo bar bazz)
```
In order to add single or multiple new elements to the end of array, you should use this syntax:
```shell
```bash
sample_array+=(six seven)
```
In order to get elements of the list in a cycle, you should use this syntax:
```shell
```bash
for i in ${sample_array[@]}
do
echo $i
@@ -31,7 +31,7 @@ done
Here is an example how to get element by its index:
```shell
```bash
echo ${sample_array[0]}
echo ${sample_array[3]}
@@ -40,7 +40,7 @@ echo ${sample_array[3]}
Array slicing:
```shell
```bash
sliced_array=${sample_array[@]:1} # will get all elements of a sample_array, starting with 1st
another_sliced_array=${sample_array[@]:1:5} # will get sample_array elements since 1st to 5th
```
@@ -48,19 +48,19 @@ another_sliced_array=${sample_array[@]:1:5} # will get sample_array elements sin
## 2. Hashmaps
To create hashmap in bash use this syntax:
```shell
```bash
declare -A sample_hashmap=([one]=one [two]=two [three]=three [four]=four [five]=five)
```
This will add new key "foo" with value "bar":
```shell
```bash
sample_hashmap[foo]=bar
```
Cycle:
```shell
```bash
for key in ${sample_hashmap[@]}
do
echo ${sample_hashmap[$key]}