Bash: Reading file into array
Assume I have a file named file.txt with the following contents
Code:
19 man Code:
dataarray=($( < file.txt )) Can someone please help me. |
www.google.com/linux is your friend for anything GNU/Linux/Unix. I entered search terms "bash array input" and found this: http://www.linuxconfig.org/Bash_scripting_Tutorial. Scroll down to "8.2. Read file into bash array".
|
Naturally it is much less elegant than what you started with,
but you could always force bash to do what you want like this: Code:
# Just to be formal, declare the array. |
Well I would think the simple loop would be fine:
Code:
while read -r line; do arr+=( "$line" ); done<file |
All times are GMT -5. The time now is 04:18 PM. |