$ echo cat /dev/stderr > bug $ bash bug 2>&- cat /dev/stderr calling bash script 2>&- on linux seems to make /dev/stderr refer to script, though &2 seems unaffected. using 2>&- inside script does not trigger this bug. i assume it is a bug and not 'historical compatibility'. the bug does not seem to appear in bash on openbsd. the bug does not seem to appear in dash or pdksh.
--- $ bash -version GNU bash, version 5.2.26(1)-release (x86_64-redhat-linux-gnu) Copyright (C) 2022 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. $ uname -srvmo Linux 6.7.6-200.fc39.x86_64 #1 SMP PREEMPT_DYNAMIC Fri Feb 23 18:27:29 UTC 2024 x86_64 GNU/Linux --- $ bash -version GNU bash, version 5.1.4(1)-release (x86_64-pc-linux-gnu) Copyright (C) 2020 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. Linux 5.10.0-28-amd64 #1 SMP Debian 5.10.209-2 (2024-01-31) x86_64 GNU/Linux ---