[SLUG] arrays

Martin Webb martin at webb.lcbroadband.co.uk
Sun Nov 27 23:50:25 GMT 2005


Hi, all,
I wrote a bash script using an array.  The script was to read a data 
file, line by line, into the array.

Data file:
this is the first line
this is the second line
etc.

But the array reads single words into each element of the array, instead 
of the whole line into an array element.  Can I get the array to read 
the whole line, from beginning to CR, all into the same array element, 
and if so how?

I'm using:
array=( `cat "$filename"`)     #  Loads contents from data file

and I get:
array[0]="this"
array[1]="is"
array[2]="the"
array[3]="first"
and so on, when what I want is:

array[0]="this is the first line"

Any ideas?
Martin







More information about the Scarborough mailing list