Re: Surprising behaviour when reading from a named pipe and standard input

Earnestly
2026-02-10T10:24:06Z

On Tue, Feb 10, 2026 at 02:00:18AM +0000, Harald van Dijk wrote:
> In bash, <&0 suppresses the implicit </dev/null, meaning the outer
> environment's stdin gets used.

I hoped that dash would do the same, when faced with an explicit use
of <&0, which I try to base on my reading of the standard:

> If, and only if, job control is disabled, the standard input for the
> subshell in which an asynchronous AND-OR list is executed shall
> initially be assigned to an open file description that behaves as if
> /dev/null had been opened for reading only. This initial assignment
> shall be overridden by any explicit redirection of standard input
> within the AND-OR list.

With emphasis on the last sentence.

You write that dash does ultimately interpret this correctly but applies
it too late, after fd 0 is already /dev/null.

Perhaps because this is not merely a no-op (as 0<&0 is) and that dash does
attempt to do the right thing (too late), it suggests maybe dash should
change behaviour.

However you're right about portable shell scripts. I have to accept the
minimal interpretation and your solution is very reasonable, perhaps even
more explicit as well.

Many thanks for your explanation.