redirecting stdin in ksh
Charles Maurer
chip at mtuni.UUCP
Sat Jan 18 05:39:17 AEST 1986
While creating a shell script using ksh, I attempted to
redirect stdin for a series of reads from a file (See
"The Unix System" by S. Bourne, pg 212). The code goes
as follows:
more="yes"
exec 3<&0 < file # dup stdin to fd 3, and redirect from file
while [ "$more" ]
do
read number age name
if [ "$?" -eq 0 ]
then
process number, age, name
else # end of file
more=""
fi
done
exec 0<&3 3<&- # redirect stdin back to fd 0, close fd 3
The input is redirected fine, but the script never regains
control from normal stdin. When I "sh" the file, it works
as it should. What should be done to achieve the same effect
through ksh? I don't need to know alternative ways of accomplishing
the same thing.
Thanks in advance,
chip maurer
mtuni!chip
More information about the Comp.unix
mailing list