On 3/29/24 9:32 AM, Greg Wooledge wrote:
On Fri, Mar 29, 2024 at 09:02:12PM +1100, Reuben wrote:$ echo cat /dev/stderr > bug $ bash bug 2>&- cat /dev/stderrI don't understand what you were trying to do here.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.As a first guess, bash was given the name of a file to read as a script, so it opened that file using the first available file descriptor. Since you had already closed FD 2 before invoking bash, FD 2 was the first available, and therefore the script was opened as FD 2.
This is pretty much right. cat's behavior depends on how the OS handles /dev/stderr. On Linux, the open succeeds and the read returns the script data. On FreeBSD, the open succeeds and the read returns 0. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, UTech, CWRU c...@case.edu http://tiswww.cwru.edu/~chet/
OpenPGP_signature.asc
Description: OpenPGP digital signature