I am wondering why
ls -1 |
while read file; do
echo $file; tail -n 100 $file > >(sleep 1 && cat > $file)
done
is faster than
ls -1 |
while read file; do
echo $file; tail -n 100 $file | (sleep 1 && cat > $file)
done
?
If there are 100 files in a directory then:
- the second command takes almost 100 seconds to process
- the first command is processed almost immediately.
bash
doesn't wait for the termination of that process substitution (which could be seen as a bug). See The process substitution output is out of the order for details.grep < <(cmd)
, while the shell doesn't wait forcmd
,grep
does as it waits for eof on its stdin. Again, see details at the link I gave in my previous comment.&
(note that background_/_foreground only apply to interactive shells, that's terminology linked to job control in terminals). process substitution are put in background unless they're run from a subshell itself run in foreground. In any case, that's not what I'm talking about. I'm talking about the shell waiting for the termination of processes it starts before continuing with the next command (tbc)&
).