set -A array $(grep "string" myFile.txt )
and
array=( $(grep "string" myFile.txt ) )
can't handle those lines correct which include more words as one.
If you need put the line to the one array element, then you need some input manipulation = line is one element.
Example, works with posix-sh (ksh, bash, ...):
i=0
array[0]=""
toarr()
{
array[$i]="$*"
((i+=1))
}
grep "string" myFile.txt | while read line
do
toarr $line
done
echo ${#array[*]}
echo ${array[*]}
i=0
cnt=${#array[*]}
while ((i<cnt))
do
echo "$i:${array[$i]}"
((i+=1))
done