bash: adjust example to read from file into array (#2187)

* use `$()` rather than deprecated ``
* illustrate shortcut for builtin read of file without `cat`
* don't imply this reads lines, it will split into words by default

perhaps the cheatsheet should have a section on IFS, but that's
off-topic for this patch.

Co-authored-by: Rico Sta. Cruz <rstacruz@users.noreply.github.com>
This commit is contained in:
Kjetil Torgrim Homme
2025-07-01 08:25:49 +10:00
committed by GitHub
co-authored by Rico Sta. Cruz
parent 1ba47a8e7e
commit b00d106985
+1 -1
View File
@@ -510,7 +510,7 @@ Fruits=( "${Fruits[@]/Ap*/}" ) # Remove by regex match
unset Fruits[2] # Remove one item
Fruits=("${Fruits[@]}") # Duplicate
Fruits=("${Fruits[@]}" "${Veggies[@]}") # Concatenate
lines=(`cat "logfile"`) # Read from file
words=($(< datafile)) # From file (split by IFS)
```
### Iteration