Skip to content

Fix >&file redirect-both regression (ambiguous redirect on /dev/null) - #314

Merged
brianjfox merged 1 commit into
mainfrom
fix/redirect-both-ampfile
Jul 25, 2026
Merged

Fix >&file redirect-both regression (ambiguous redirect on /dev/null)#314
brianjfox merged 1 commit into
mainfrom
fix/redirect-both-ampfile

Conversation

@brianjfox

Copy link
Copy Markdown
Owner

Fixes #313. Regression from #306.

Batch 95's dup-target validation (<&word/>&word must be an fd number, else ambiguous redirect) also rejected the bare >&file form, which bash treats as redirecting both stdout and stderr to the file (&>file). A login shell whose startup files use >&/dev/null then failed with /dev/null: ambiguous redirect.

Now a bare >& (no explicit source fd) with a non-fd word opens the file (honoring noclobber) and dups it onto fd 1 and fd 2, matching bash. 2>&file (explicit fd) and <&file correctly remain ambiguous.

echo hi >&/dev/null                       # no output (both streams discarded)
{ echo o; echo e >&2; } >&f; cat f        # o / e     (both captured)
echo hi 2>&/dev/null                       # ambiguous redirect  (unchanged)
cat <&/dev/null                            # ambiguous redirect  (unchanged)

ctest 22/22, run_diff all 234 scripts match bash. The redir scoreboard improves further (130 → 122) since the redirect-both form is now correct.

…rect

The dup-target fd validation added for ambiguous `<&word'/`2>&word'
redirects also rejected the bare `>&word' form whose word is a filename
-- bash's shorthand for sending both stdout and stderr to that file
(`&>word').  A login shell whose startup files used `>&/dev/null' then
failed with `ambiguous redirect'.

When `>&' carries no explicit source fd and the word is not an fd number,
open the file (honoring noclobber) and dup it onto both fd 1 and fd 2,
matching bash.  An explicit source fd (`2>&file') or an input dup
(`<&file') with a non-fd word stays an ambiguous redirect.

Closes #313
@brianjfox
brianjfox merged commit b2719d2 into main Jul 25, 2026
1 check passed
@brianjfox
brianjfox deleted the fix/redirect-both-ampfile branch July 25, 2026 19:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Regression: bare >&file redirect-both reported as 'ambiguous redirect'

1 participant