2018-05-02 11:52:09 +0200, Joerg Schilling: > Stephane Chazelas <stephane.chaze...@gmail.com> wrote: > > > 2018-04-27 20:28:57 +0200, Martijn Dekker: > > [...] > > > : <&8 || echo "oops, closed" > > [...] > > > > Remember ":" is a special builtin, so its failure causes the > > shell to exit. Another one of those accidents of implementation > > of the Bourne shell that ended up being specified by POSIX, but > > which makes little sense (but that other shells ended up > > implementing for conformance). > > The background seems to be a bit more complex: > > sh -c ' : <&8; echo bla' # Solaris 11 Bourne Shell > bla
Here the problem is that the Bourne shell silently ignored the failing of those "dup2()" redirections. $ echo test | sh -c 'cat <&8; echo OK' test OK That bug was fixed in ksh and all other shells. But otherwise, a failing ":" still causes the shell to exit: $ sh -c 'echo < /x; echo OK' sh: /x: cannot open [...] > bash -c ' : <&8; echo bla' > bash: 8: Falsche Dateinummer > bla > > So: > > 1) before POSIX, ":" could not fail > > 2) bash ignores the "new" rules. [...] Not really, it's POSIX again specifying an accident of implementation in the Korn shell (in this case inherited from the Bourne shell, so a "very old" rule). Here, it's a silly requirement. Nobody would expect a failure of the no-op command to exit the shell. That's why bash, zsh and yash only do it in conformance mode (when called as "sh"). $ (exec -a sh bash -c ': <&8; echo X') sh: 8: Bad file descriptor -- Stephane