mirror of
https://github.com/fish-shell/fish-shell.git
synced 2026-05-14 22:11:16 -03:00
Reallow "2>>&1" as a redirection
Appending to an fd doesn't really make sense, but we allowed the syntax previously and it was actually used. It's not too harmful to allow it, so let's just do that again. For the record: Zsh also allows it, bash doesn't. Fixes #6614
This commit is contained in:
@@ -362,6 +362,7 @@ maybe_t<pipe_or_redir_t> pipe_or_redir_t::from_string(const wchar_t *buff) {
|
||||
}
|
||||
case L'>': {
|
||||
consume(L'>');
|
||||
if (try_consume(L'>')) result.mode = redirection_mode_t::append;
|
||||
if (try_consume(L'|')) {
|
||||
// Note we differ from bash here.
|
||||
// Consider `echo foo 2>| bar`
|
||||
@@ -374,6 +375,7 @@ maybe_t<pipe_or_redir_t> pipe_or_redir_t::from_string(const wchar_t *buff) {
|
||||
: STDOUT_FILENO; // like >|
|
||||
} else if (try_consume(L'&')) {
|
||||
// This is a redirection to an fd.
|
||||
// Note that we allow ">>&", but it's still just writing to the fd - "appending" to it doesn't make sense.
|
||||
result.mode = redirection_mode_t::fd;
|
||||
result.fd = has_fd ? parse_fd(fd_start, fd_end) // like 1>&2
|
||||
: STDOUT_FILENO; // like >&2
|
||||
@@ -381,11 +383,10 @@ maybe_t<pipe_or_redir_t> pipe_or_redir_t::from_string(const wchar_t *buff) {
|
||||
// This is a redirection to a file.
|
||||
result.fd = has_fd ? parse_fd(fd_start, fd_end) // like 1> file.txt
|
||||
: STDOUT_FILENO; // like > file.txt
|
||||
if (result.mode != redirection_mode_t::append) result.mode = redirection_mode_t::overwrite;
|
||||
// Note 'echo abc >>? file' is valid: it means append and noclobber.
|
||||
// But here "noclobber" means the file must not exist, so appending
|
||||
// can be ignored.
|
||||
result.mode = redirection_mode_t::overwrite;
|
||||
if (try_consume(L'>')) result.mode = redirection_mode_t::append;
|
||||
if (try_consume(L'?')) result.mode = redirection_mode_t::noclob;
|
||||
}
|
||||
break;
|
||||
|
||||
Reference in New Issue
Block a user