On 10/27/2010 09:30 PM, Paul Eggert wrote:
> OpenBSD /bin/sh, and some other sh variants, squirrel away file
> descriptors before closing them.

ALL shells squirrel away file descriptors before closing them for the
duration of a builtin command, if there is a chance that a later shell
command will be executed that no longer needs the temporary closure.

It's just that ksh is a bit smarter about recognizing the last command
in a script, and doesn't squirrel away when there are no subsequent
commands that could possible need the fd.  But as was pointed out on the
dash list, this means that ksh is buggy when there is an exit trap
installed such that there really ARE commands after the last command of
the script:

$ ksh93 -c ':; trap "echo hi" EXIT >/dev/null'
$

All other shells output hi, because the redirection to /dev/null should
only have lasted for the duration of installing the trap, and not for
the actual execution of the trap.

-- 
Eric Blake   ebl...@redhat.com    +1-801-349-2682
Libvirt virtualization library http://libvirt.org

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to