Autosave: 2023-02-04 09:26:34

This commit is contained in:
thomasabishop 2023-02-04 09:26:34 +00:00
parent e982d1a6ab
commit f475ad9be2
2 changed files with 31 additions and 2 deletions

View file

@ -0,0 +1,15 @@
---
categories:
- Programming Languages
tags:
- shell
---
# Loops in bash
```bash
for element in "${arr[@]}"
do
echo "$element"
done
```

View file

@ -9,8 +9,7 @@ tags:
## `readarray`
`readarray` makes it really easy to split input into an array.
`readarray` makes it really easy to split input into an array based on new lines.
Say we have this file as input:
```
@ -48,3 +47,18 @@ is
> The _-t_ flag removes the trailing newline
Add more: https://linuxhint.com/split-string-array-bash/
## `read`
For different delimiters we have to use `read`, combined with `IFS` the **Internal Field Separator**.
For example, to split by comma:
```plaintext
# comma-input.txt
something, something else, something more
```
```bash
IFS=',' read -a arr < ./comma_inputs.txt
```