On Sat, Sep 04, 2010 at 08:20:33PM +0200, Steve Schnepp wrote: > 2010/9/3 Jilles Tjoelker <jilles@xxxxxxxx>: > > This patch assumes that the file descriptor is discarded afterwards (its > > position does not matter). Therefore the very common construct > > while read x; do > > ... > > done > > stops working. > Ohh.. thanks for that, I didn't see it. > Actually "while read x" continues to work. > But "reopening the file" doesn't as in : > read a b < datafile > echo ${a} ${b} > read a b < datafile > echo ${a} ${b} You're right, it's even stranger than I expected. > I attached an updated patch that corrects this pb by discarding the > buffer when opening a new file. This discarding is still bad as it throws away valid data if the open file description is shared. This happens if stdin is redirected inside a while read... loop. Furthermore, I think constructions like read x; cat and read x; (read y); read z should keep working. This requires that the input's file position be synced whenever another process may see it (fork/exit). Due to the highly dynamic character of the shell and the common use of fd 0, this probably means that you can't do better than syncing after each read builtin. (For example, 'read' could be overridden with a function after the third line.) Another thought: exec 3<&0; read x; read y <&3 or even sh -c 'read x; read y <&3' 3<&0 Different file descriptors may refer to the same open file description and the shell may not know this. -- Jilles Tjoelker -- To unsubscribe from this list: send the line "unsubscribe dash" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html