Files
cheatsheet-tldr/tldr/readarray
2024-12-29 00:19:25 +00:00

26 lines
630 B
Plaintext

---
syntax: markdown
tags: [tldr, common]
source: https://github.com/tldr-pages/tldr.git
---
# 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}}`
- Copy at most the specified number of lines:
`readarray -n {{N}} {{array_name}} < {{path/to/file.txt}}`