2024-12-29 00:31:56 +02:00
|
|
|
# readarray
|
|
|
|
|
|
|
|
> Read lines from `stdin` into an array.
|
|
|
|
> More information: <https://www.gnu.org/software/bash/manual/bash.html#index-readarray>.
|
|
|
|
|
|
|
|
- Interactively input lines into an array:
|
|
|
|
|
|
|
|
`readarray {{array_name}}`
|
|
|
|
|
|
|
|
- Read lines from a file and insert them in an array:
|
|
|
|
|
|
|
|
`readarray {{array_name}} < {{path/to/file.txt}}`
|
|
|
|
|
|
|
|
- Remove trailing deliminators (newline by default):
|
|
|
|
|
|
|
|
`readarray -t {{array_name}} < {{path/to/file.txt}}`
|
|
|
|
|
2025-03-27 15:53:12 +00:00
|
|
|
- Copy at most `n` lines:
|
2024-12-29 00:31:56 +02:00
|
|
|
|
2025-03-27 15:53:12 +00:00
|
|
|
`readarray -n {{n}} {{array_name}} < {{path/to/file.txt}}`
|
2025-03-26 00:36:41 +02:00
|
|
|
|
|
|
|
- Display help:
|
|
|
|
|
|
|
|
`help mapfile`
|