Problem with array sizes

If I do :-

set -A classifications atype btype ctype dtype etype
for i in ${classifications[@]}
do
echo $i
print $i >> /tmp/class.txt
done

print "${#classifications[@]}"

The array prints as I would expect and the size of the array is 5 (as expected).

If I use an alternative method:

i=0
exec < /tmp/classifications.txt
while read array [i]; do
echo ${array
[i]((i=i+1))
done

print "${#array[@]}"

The array size is 6. I can't figure out why ? Anyone explain this please?

Thanks for your help.

Having hada bit of a play with your code, it looks as though the array size is being incremented by the read statement. If you change the code to...

while read line ; do
array=line
.
.

the final size comes out at 5.

Does look like a bit of an anomaly!:confused:

Cheers. I suspect you are right :slight_smile: