Agreed, every time I've used a named pipe in a shellscript it's caused me nothing but pain.
IIRC, they're guaranteed not to interleave write()s less than PIPE_BUF (4k?) but if your program is buffering internally it might not end writes on a newline.
You don't need named pipes for this:
{ ./prog1; ./prog2; } | sort | uniq -u
Does:
sort < foo | uniq -u
not work with named pipes?It works fine.
The advantage to
cat foo | sort | uniq -u
is that it is (marginally) easier to drop in another filter in front of sort.This argument is less strong in the face of:
<foo sort | uniq -u
(redirections can be at the beginning too.)Also: sort -u instead of sort|uniq.
It's still a reason to disprefer the form that was given. I don't see any reason to prefer the cat version over yours, except habits, though. That said, there's only weak reason to avoid the cat.
Having said that, I have had occasion to use named pipes in a shell script. Basically, I had two programs and I wanted to determine which lines were in one, but not both, of their outputs. Using named pipes, I was able to do something like:
Effectively, this provides a way to combine the output of multiple commands. I took it as a matter of faith that doing this won't interleave lines. I assume that as long as both programs flush only at line breaks then there is not any problem.