Pipes and variable scoping inside korn shell scripts

It seems that per ksh '93 spec (and maybe earlier) doing something like
---
cat filename |while read $col1 $col2; do
 array($i)=$col1
 echo ${#array[@]}
done

echo ${#array[@]}
---
causes, for a 5 line file, output of
1
2
3
4
5
0
seemingly because in that ksh spec the pipes run as separate processes.  However, I really need to keep the contents of the array outside the loop.  What can I do?  Am I even misinterpreting the spec?  As a related question, how do I find out which version of ksh I'm running?  FYI, I have a Linux RedHat 6.0 install.

boromirAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ecwCommented:
Use posix shell or

---
exec 3<filename
while read col1 col2 <&3 ; do
 array($i)=$col1
 echo ${#array[@]}
done

echo ${#array[@]}
---

ie. use exec to open filename on fd 3, and read from that.  this will work in ksh and sh.  a ksh specific would be -
  while read -u3 col1 col2 ; do

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
boromirAuthor Commented:
Thanks!  Exactly on target!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.