Martijn Dekker <mart...@inlv.org> wrote:
> $ dash -c '{ exec 8</dev/null; } 8<&-; : <&8 && echo "oops, still open"'
> Output: "oops, still open"
> Expected output: Bad file descriptor

Well if you deconstruct the redirection it actually says

1) Close fd 8.
2) Open /dev/null and redirect to fd 8.

The second part is done by exec and therefore must remain in the
current shell execution environment.  So dash's behaviour is
compliant.

However, POSIX also allows file descriptors greater than 3 to be
closed in this case:

        If exec is specified without command or arguments, and any
        file descriptors with numbers greater than 2 are opened with
        associated redirection statements, it is unspecified whether
        those file descriptors remain open when the shell invokes another
        utility. Scripts concerned that child shells could misuse open
        file descriptors can always close them explicitly, as shown in
        one of the following examples.

This allows for the behaviour of the other shells.

Cheers,
-- 
Email: Herbert Xu <herb...@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt
--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to majord...@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to