There is a file containing strings. How to read these lines from a file into an array in bash?
2 answers
So much easier:
readarray ARRAY < filename
- why minus The answer is absolutely correct (for bash 4). I would give the
-t
option to remove the line feed. - jfs
|
read:
index=0 while read line; do array[$index]="$line" index=$(($index+1)) done < filename
check:
for ((a=0; a < ${#array[*]}; a++)) do echo "$a: ${array[$a]}" done
|