1
0
mirror of https://github.com/onkelbeh/cheatsheets.git synced 2026-08-15 13:34:53 +02:00

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 00:25:49 +02:00
committed by GitHub
parent 1ba47a8e7e
commit b00d106985

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