Link to home
Start Free TrialLog in
Avatar of boromir
boromir

asked on

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.

ASKER CERTIFIED SOLUTION
Avatar of ecw
ecw

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of boromir
boromir

ASKER

Thanks!  Exactly on target!