mapfile
Read lines from the standard input into an indexed array variable.[1]
Documentation
- mapfile [EN] @ GNU Bash Reference Manual
- bash -c 'help mapfile'
- man 1 'bash' [EN]
Syntax
mapfile [PARAMETER ...] [ARRAY]
Parameters
- -d DELIMITER
- Use DELIMITER to terminate lines, instead of newline.
- -n NUMBER
- Copy at most NUMBER lines. If NUMBER is 0, all lines are copied.
- -t
- Remove a trailing DELIMITER from each line read (default newline).
- -s NUMBER
- Discard the first NUMBER lines read.
Examples
- Find all variables with the name pattern machine_ & store them to the array machines
mapfile -t 'machines' < <(compgen -v 'machine_')
References
- ↑ bash -c 'help mapfile'