while read line stops after first iteration [duplicate] while read line stops after first iteration [duplicate] unix unix

while read line stops after first iteration [duplicate]


Redirect your inner command's stdin from /dev/null:

svmatch $line </dev/null

Otherwise, svmatch is able to consume stdin (which, of course, is the list of remaining lines).

The other approach is to use a file descriptor other than the default of stdin:

#!/bin/shwhile IFS= read -r line <&3; do  svmatch "$line"done 3<svr_input

...if using bash rather than /bin/sh, you have some other options as well; for instance, bash 4.1 or newer can allocate a free file descriptor, rather than requiring a specific FD number to be hardcoded:

#!/bin/bashwhile IFS= read -r -u "$fd_num" line; do  do-something-with "$line"done {fd_num}<svr_input