With the script below, I'd expect any fd pointing to /dev/null to be closed when the second llfd() is executed. Surprisingly, fd 3 is closed, but fd 10 is now open, pointing to /dev/null, as if eval copied it instead of closing it. Is this a bug?
Thanks, M $ bash -c 'llfd () { ls -l /proc/$BASHPID/fd/; }; x=3; eval "exec $x>/dev/null"; llfd; eval "llfd $x>&-"' total 0 lrwx------ 1 matei matei 64 Feb 11 18:36 0 -> /dev/pts/2 lrwx------ 1 matei matei 64 Feb 11 18:36 1 -> /dev/pts/2 lrwx------ 1 matei matei 64 Feb 11 18:36 2 -> /dev/pts/2 l-wx------ 1 matei matei 64 Feb 11 18:36 3 -> /dev/null lr-x------ 1 matei matei 64 Feb 11 18:36 8 -> /proc/4520/auxv total 0 lrwx------ 1 matei matei 64 Feb 11 18:36 0 -> /dev/pts/2 lrwx------ 1 matei matei 64 Feb 11 18:36 1 -> /dev/pts/2 l-wx------ 1 matei matei 64 Feb 11 18:36 10 -> /dev/null lrwx------ 1 matei matei 64 Feb 11 18:36 2 -> /dev/pts/2 lr-x------ 1 matei matei 64 Feb 11 18:36 8 -> /proc/4520/auxv $ bash --version GNU bash, version 4.2.24(1)-release (x86_64-pc-linux-gnu) Copyright (C) 2011 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software; you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. $