[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: > /dev/stderr 2>&-
From: |
Greg Wooledge |
Subject: |
Re: > /dev/stderr 2>&- |
Date: |
Fri, 29 Mar 2024 09:32:37 -0400 |
On Fri, Mar 29, 2024 at 09:02:12PM +1100, Reuben wrote:
> $ echo cat /dev/stderr > bug
> $ bash bug 2>&-
> cat /dev/stderr
I 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.
To me, this seems like a case of "Doctor, it hurts when I bend my arm
this way." Maybe Chet will disagree.