You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
read builtin: empty from /dev/fd/N, and rc=0 at EOF under compound/fd redirection (while read off-by-one) #701
Two read-builtin divergences: it reads empty from /dev/fd/N, and it returns success at EOF-without-newline when the redirection is attached to a compound command or an inherited fd — which makes the classic while read loop run one extra iteration. Both confirmed against real GNU bash.
Environment: Niubash 1.4.0 · rubash git e785c3c8f610 — Windows 10 x64. Method: differential vs GNU bash 5.2.21(1) / 5.3.0.
R3.1 read builtin reads empty from /dev/fd/N
$ printf'DATA\n'> f ;exec6< f
$ read -r z < /dev/fd/6 ;echo"[$z]"
niu : [] # empty
bash: [DATA]
Same for /dev/fd/0. External commands on the same path are correct:
$ cat /dev/fd/6
niu : DATA # works
Writing to /dev/fd/N also works. Only the read builtin's read path is affected.
R3.2 read returns 0 at EOF-without-newline under compound / fd redirection
$ printf'abc'> f
$ { IFS= read -r l;echo"rc=$?"; } < f
niu : rc=0 bash: rc=1
$ exec9< f ; IFS= read -r l <&9 ;echo"rc=$?"
niu : rc=0 bash: rc=1
The simple-command form is correct, and so are the pipe form and mapfile:
$ IFS= read -r l < f ;echo"rc=$?"
niu : rc=1 bash: rc=1 # OK
Effect on the most common loop idiom — a file whose last line lacks \n:
Version note (correction to the Method line): the oracle was reached with bare wsl.exe -e bash, which resolves through PATH to /usr/local/bin/bash = GNU bash 5.3.0(1) — not 5.2.21. The 5.2.21 build lives at /bin/bash, and every item in this report was re-checked on it as well; results were identical on both.
So the two versions are listed in the wrong order above: 5.3.0 was the default, 5.2.21 the cross-check.
No finding here changes; noting it only so the numbers reproduce. (Incidentally 5.3.0 is also the oracle cited in rubash#641, "the repository oracle is WSL 5.3.0".)
Activity
caomengxuan666 commentedon Oct 17, 2026
Version note (correction to the Method line): the oracle was reached with bare
wsl.exe -e bash, which resolves through PATH to/usr/local/bin/bash= GNU bash 5.3.0(1) — not 5.2.21. The 5.2.21 build lives at/bin/bash, and every item in this report was re-checked on it as well; results were identical on both.So the two versions are listed in the wrong order above: 5.3.0 was the default, 5.2.21 the cross-check.
No finding here changes; noting it only so the numbers reproduce. (Incidentally 5.3.0 is also the oracle cited in rubash#641, "the repository oracle is WSL 5.3.0".)
fix(read): resolve /dev/stdin + EOF-without-delimiter in the read bui…
fix(read): serve fd-0 self-dups through the ordinary fd-0 transports (#…