chip@mtuni.UUCP (Charles Maurer) (01/17/86)
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
gwyn@brl-tgr.ARPA (Doug Gwyn <gwyn>) (01/20/86)
> 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 My guess is that ksh closed down all fds other than 0,1,2 when execing a command inside the loop.