XPost: comp.unix.shell
Op 05-12-19 om 13:36 schreef
[email protected]:
In article <[email protected]>,
Martijn Dekker <[email protected]> wrote:
The following should be POSIXly correct and portable, right?
$ mkfifo f1 f2
$ (ls >f1 & ls -a >f2 & diff f1 f2)
Expected output: difference between 'ls' and 'ls -a' output.
(The (subshell) is just for suppressing job control noise.)
This works on every unixy system, it seems, *except* Solaris, which
quietly detects no difference. It fails at least on Solaris 10.1 through
11.4, as well as OpenIndiana.
You are mistaken, it works on every UNIX the way it does on Solaris... _except_ when the platform used "gdiff".
This includes e.g. older versions of FreeBSD but not any newer *BSD since *BSD
tris to avoid non-free licenses since a while.
You should really check before making authoritative statements,
especially if they're so easy to prove wrong.
It *does* work on the current FreeBSD release, with FreeBSD diff. Try
it. I tried it, before posting.
It also works on the current NetBSD and OpenBSD releases. None of them
use GNU diff.
I didn't bother with testing older Free/Net/OpenBSD releases but I would
be surprised if it ever did *not* work.
I even confirmed that it works on Interix, and it is *old* and doesn't
use GNU diff either.
I would say, there is still a bug in the UNIX diff, but this differs from what
you believe:
diff should probably print that there was a seek error....
because you cannot seek a pipe.
Of course, you cannot. However, it is easy to show that diff works fine
with a pipe on Solaris, as long as that pipe is not a FIFO:
On Solaris 11.4:
$ type diff
diff is /usr/bin/diff
$ ls > tmpfile
$ ls -a | diff tmpfile /dev/stdin
0a1,18
.
..
(etc)
$ mkfifo F1 F2
$ ls >F1 & ls -a >F2 &
$ diff /dev/fd/4 /dev/fd/5 4<F1 5<F2
.
..
(etc)
When /dev/stdin or /dev/fd/* are connected to pipes, you can't seek them
any more than you can directly seek a FIFO. Yet, the above works.
And there is no reason why it shouldn't work. Diff is a linear
operation, so seeking is not necessary. At most it's an optimisation,
and optimisations can be disabled.
Clearly, then, Solaris diff does not, and does not need to, require the
ability to seek. It's got some very specific problem with being given a
FIFO directly as an argument, that's all.
I don't know whether that strange behaviour is POSIX compliant or not (I
now strongly suspect it's not, though) but it certainly looks like a
bug. There is zero reason why that shouldn't work.
The reason why your proposal diff <(cat f1) <(cat f2) works is because the output of cat is directed to a /tmp/ file that is openend and passwed as /dev/fd/# to diff.
This statement cannot possibly be right. Not only would it defeat the
purpose of process substitution to use temporary files, but it would be impossible.
By definition, process substitution is processed asynchronously. The
commands invoked are background jobs. Temporary files do not provide the required blocking mechanism. You need a pipe (FIFO or otherwise).
- M.
--
/ modernish -- harness the shell \
https://github.com/modernish/modernish
--- SoupGate-Win32 v1.05
* Origin: fsxNet Usenet Gateway (21:1/5)