On 20/03/2025 11:59, Geoff Clare via austin-group-l at The Open Group wrote:
Harald van Dijk wrote, on 20 Mar 2025:
On 20/03/2025 11:04, Geoff Clare via austin-group-l at The Open Group wrote:
Chet Ramey wrote, on 18 Mar 2025:
The original language, from 1992, is "In all cases, explicit redirection
of standard input shall override this activity." Bash interpreted that to
mean that the implicit redirection of didn't happen.
The input we need from you on 0<&0 is, given that bash's behaviour
differs from the other shells whose behaviour we normally take into
consideration, do you think the resolution of bug 1913 should allow
the current bash behaviour or will you change bash to behave like
those other shells?
This is one corner case where bash's behaviour differs from other shells but
outside of that corner case, bash's behaviour matches other significant
shells and you are suggesting changing POSIX to no longer permit this. Let
me make this clearer with examples.
$ echo hello | bash -o posix -c "{ cat & wait; }"
$ echo hello | bash -o posix -c "{ cat & wait; } 0<&0"
hello
$ echo hello | ksh -o posix -c "{ cat & wait; }"
$ echo hello | ksh -o posix -c "{ cat & wait; } 0<&0"
hello
$ echo hello | bosh -c "{ cat & wait; }"
$ echo hello | bosh -c "{ cat & wait; } 0<&0"
hello
$ echo hello | pbosh -c "{ cat & wait; }"
$ echo hello | pbosh -c "{ cat & wait; } 0<&0"
hello
I see these as not so much about 0<&0 but the other (asynchronous
list) issue. They are special cases of commands where redirections
done before an asynchronous list is started affect whether the
redirection from /dev/null is done.
Yes, this is based on the "This initial assignment shall be overridden
by any explicit redirection of standard input within the AND-OR list."
See below.
The one with 0<&0 was only
previously allowed because 0<&0 had unspecified behaviour;
As Lawrence Velázquez commented elsethread, the rationale includes an
instance of <&0 that has been there since at least SUSv2 that
demonstrates that this was always intended to be valid and to leave
stdin unchanged, even if the normative wording failed to specify this.
the other
cases have never been allowed by POSIX. For example:
$ echo hello > FIFO & bash -o posix -c "{ cat & wait; } 0<FIFO"
[1] 3690
hello
$ echo hello > FIFO & ksh93u+m -o posix -c "{ cat & wait; } 0<FIFO"
[1] 3699
hello
The sentence is ambiguous as to whether "within the AND-OR list" applies
to "explicit redirection" or to "standard input" and the above shells
have taken it to apply to "standard input": even though the redirection
is outside of the AND-OR list, the standard input within the AND-OR
list, which is the standard input which was inherited from outside the
AND-OR list, has been explicitly redirected. This is a perfectly valid
and sensible interpretation, and if the shells have always worked that
way, I very much expect it was the originally intended interpretation.
Cheers,
Harald van Dijk