Martijn Dekker <> 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

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.

Email: Herbert Xu <>
Home Page:
PGP Key:
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to
More majordomo info at

Reply via email to