readarray
shell builtinLinux/Unix
The readarray command is one of the most frequently used commands in Linux/Unix-like operating systems. readarray Read lines from standard input into an array variable
Quick Reference
Command Name:
readarray
Category:
shell builtin
Platform:
Linux/Unix
Basic Usage:
readarray [options] [arguments]
Common Use Cases
Syntax
readarray [options] array
Options
Option | Description |
---|---|
-c count |
Display a line count when reading every COUNT lines |
-C callback |
Evaluate CALLBACK each time COUNT lines are read |
-d delim |
Use DELIM to terminate lines, instead of newline |
-n count |
Read at most COUNT lines |
-O origin |
Begin assigning to array at index ORIGIN (default is 0) |
-s count |
Skip the first COUNT lines read |
-t |
Remove trailing delimiter (newline by default) from each line read |
-u fd |
Read from file descriptor FD instead of standard input |
-z |
Line ends with NULL character, not newline |
Examples
How to Use These Examples
The examples below show common ways to use the readarray
command. Try them in your terminal to see the results. You can copy any example by clicking on the code block.
# Basic Examples Basic
readarray my_arraycat file.txt | readarray lines