Hi,
bash-5.1 (and judging from git blame, all versions that ever supported
lastpipe, so 4.2+) fails to honor lastpipe when run without fd 0:
$ bash -O lastpipe -c 'echo x | read x; echo x=$x'
x=x
$ bash -O lastpipe -c 'echo x | read x; echo x=$x' <&-
x=
$ bash -O lastpipe -c 'exec </dev/null; echo x | read x; echo x=$x' <&-
x=x
The issue seems to be that execute_cmd.c:execute_pipeline insists on
saving/restoring stdin which obviously fails when there's no stdin open
at all:
lstdin = move_to_high_fd (0, 1, -1);
if (lstdin > 0)
/* lastpipe in effect here */
(I got bitten by this because acpid runs action scripts with closed
stdin, so lastpipe doesn't work in those while the same script invoked
manually works. I wish bash gave me a warning instead of silently
falling back to non-lastpipe behaviour.)
--
Tomáš Janoušek, a.k.a. Pivník, a.k.a. Liskni_si, https://work.lisk.in/