Reading an entire file into an array
suggest changeread -a reads only one line, then splits that line. It does not load the whole file:
IFS=$'\n' read -r -a arr < file
Reading in a loop:
arr=()
while IFS= read -r line; do
arr+=("$line")
done < file
Using mapfile or readarray (which are synonymous):
mapfile -t arr < file
readarray -t arr < file
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents