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
Five redirection / file-descriptor divergences from GNU bash, all with minimal repros and confirmed on the real bash over repeated runs.
Environment: Niubash 1.4.0 · rubash git e785c3c8f610 · winuxcmd 1.1.12 — Windows 10 x64 (build 19045). Method: differential run against GNU bash 5.2.21(1) (cross-checked on 5.3.0); each item below is a minimal deterministic repro verified on both shells.
R1.1 2>&1 >file applies redirections in the wrong order
$ { echo OUT;echo ERR >&2; } 2>&1>f ;echo"file=[$(cat f)]"
niu : file=[OUT
ERR] ; nothing on stderr
bash: file=[OUT] ; ERR goes to the original stdout
Real impact — the common idiom cmd 2>&1 >/dev/null:
Same defect with 1>&2 2>file (both land in the file). The safe order >file 2>&1 is correct.
R1.2 Builtin write errors are not sent to the command's redirected stderr
$ printf'ro\n'> f;exec4< f
$ echo X >&42>/tmp/err ; wc -c < /tmp/err
niu : 0 # diagnostic went to the shell's own stderr instead
bash: 60
R1.3 Closing stderr corrupts an applet's exit status and emits a spurious diagnostic
$ ls /nonexistent 2>&- ;echo$?
niu :"ls: write error: Bad file descriptor" (on the closed fd's real stderr) ; rc=1bash: (silent) ; rc=2$ cat /nonexistent 2>&- ; echo $?niu : "cat: write error: Bad file descriptor" ; rc=1bash: (silent) ; rc=1
Two problems: the diagnostic is emitted even though fd 2 was closed, and ls's status is 1 instead of 2.
R1.4 cd diagnostics escape stderr redirection when run in a subshell
$ ( cd /no_such_zzz ) 2>e ; wc -c < e
niu : 0 # message bypasses the shell's fd table, goes to real stderr
bash: 69
$ ( cd /no_such_zzz ) 2>&1| wc -l
niu : 0 bash: 1
cd /no_such_zzz 2>e (not in a subshell) is captured, and { cd …; } 2>&1 is captured. Other builtins (source, set -o bad, umask, read -u) and external commands are captured correctly. Specific to the directory-changing builtins.
R1.5 bare cat fast path changes cat FILE > FILE / >> semantics
$ printf'hello\nworld\n'> f ; cat f > f ; wc -c < f
niu : 12 (file unchanged)
bash: 0 (truncated; bash also prints "cat: input file is output file")
$ printf'hello\nworld\n'> f ; cat f >> f ; wc -c < f
niu : 24 (doubled)
bash: 12
Only bare cat is affected. command cat, and python/od/cut/sort/grep/sed self-redirects, all truncate like bash. Likely related to the same inline fast path noted in unixwin/niubash#383.
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".)
Status: a fix PR for all five findings is in flight (reproduction-first, 2>&1 >file ordering as the headline item, same review bar as the other current rubash PRs). It will reference this issue in the body — leaving this note so nobody starts it in parallel. If you plan to rebalance, redirect instead.
R1.1b (f(){…} 2>&1 >f; call-site) — does not reproduce on either base; call-site function redirects are already ordered correctly (tested byte-identical).
R1.5 (bare cat f > f / >>) — does not reproduce on either base: { cat f > f; } truncates (0 of original bytes gone), cat f >> f appends (12/12), i.e. the output/operand identity handling is already correct. The only observable difference vs GNU is a missing cat: f: input file is output file warning (rc behavior fine). The numbers quoted in the report (0/12 divergences, "left"/"right" mismatch) were not observable here on either binary.
If your R1.5 measurement came from a differently-built binary (older tag / different toolchain), please state which — that would make it a build-specific defect rather than a current one.
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".)
caomengxuan666 commentedon Oct 17, 2026
Status: a fix PR for all five findings is in flight (reproduction-first,
2>&1 >fileordering as the headline item, same review bar as the other current rubash PRs). It will reference this issue in the body — leaving this note so nobody starts it in parallel. If you plan to rebalance, redirect instead.caomengxuan666 commentedon Oct 17, 2026
Verification status against this issue, from PR #725 (
fix/699-redirection-order, oracle: WSL bash 5.3.0 cross-checked on Git bash 5.2.37):niu(rubashe785c3c8f610) and onorigin/master, and all are fixed by PR fix(executor): apply redirections left to right (#699) #725.f(){…} 2>&1 >f; call-site) — does not reproduce on either base; call-site function redirects are already ordered correctly (tested byte-identical).cat f > f/>>) — does not reproduce on either base:{ cat f > f; }truncates (0 of original bytes gone),cat f >> fappends (12/12), i.e. the output/operand identity handling is already correct. The only observable difference vs GNU is a missingcat: f: input file is output filewarning (rc behavior fine). The numbers quoted in the report (0/12divergences, "left"/"right" mismatch) were not observable here on either binary.If your R1.5 measurement came from a differently-built binary (older tag / different toolchain), please state which — that would make it a build-specific defect rather than a current one.
fix(executor): apply redirections left to right (#699) (#725)
fix(executor): redirection leftovers from #699 (#726) (#783)