Fix >&file redirect-both regression (ambiguous redirect on /dev/null) - #314
Merged
Conversation
…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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #313. Regression from #306.
Batch 95's dup-target validation (
<&word/>&wordmust be an fd number, else ambiguous redirect) also rejected the bare>&fileform, which bash treats as redirecting both stdout and stderr to the file (&>file). A login shell whose startup files use>&/dev/nullthen 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<&filecorrectly remain ambiguous.ctest22/22,run_diffall 234 scripts match bash. Theredirscoreboard improves further (130 → 122) since the redirect-both form is now correct.