mirror of
https://github.com/fish-shell/fish-shell.git
synced 2025-03-15 23:22:53 +08:00
Add a special error message for |&
This commit is contained in:
parent
2a92e66902
commit
0bfd897ee0
@ -36,6 +36,8 @@ const wchar_t *tokenizer_get_error_message(tokenizer_error_t err) {
|
||||
return _(L"Invalid input/output redirection");
|
||||
case tokenizer_error_t::invalid_pipe:
|
||||
return _(L"Cannot use stdin (fd 0) as pipe output");
|
||||
case tokenizer_error_t::invalid_pipe_ampersand:
|
||||
return _(L"|& is not valid. In fish, use &| to pipe both stdout and stderr.");
|
||||
case tokenizer_error_t::closing_unopened_subshell:
|
||||
return _(L"Unexpected ')' for unopened parenthesis");
|
||||
case tokenizer_error_t::illegal_slice:
|
||||
@ -570,6 +572,10 @@ maybe_t<tok_t> tokenizer_t::next() {
|
||||
result->offset = start_pos;
|
||||
result->length = 2;
|
||||
this->buff += 2;
|
||||
} else if (this->buff[1] == L'&') {
|
||||
// |& is a bashism; in fish it's &|.
|
||||
return this->call_error(tokenizer_error_t::invalid_pipe_ampersand, this->buff,
|
||||
this->buff);
|
||||
} else {
|
||||
auto pipe = pipe_or_redir_t::from_string(buff);
|
||||
assert(pipe.has_value() && pipe->is_pipe &&
|
||||
|
@ -51,6 +51,7 @@ enum class tokenizer_error_t {
|
||||
unterminated_escape,
|
||||
invalid_redirect,
|
||||
invalid_pipe,
|
||||
invalid_pipe_ampersand,
|
||||
closing_unopened_subshell,
|
||||
illegal_slice,
|
||||
closing_unopened_brace,
|
||||
|
@ -24,4 +24,9 @@ cat $tmpdir/file.txt
|
||||
echo noclobber &>>? $tmpdir/file.txt
|
||||
#CHECKERR: {{.*}} The file {{.*}} already exists
|
||||
|
||||
eval "echo foo |& false"
|
||||
#CHECKERR: {{.*}} |& is not valid. In fish, use &| to pipe both stdout and stderr.
|
||||
#CHECKERR: echo foo |& false
|
||||
#CHECKERR: ^
|
||||
|
||||
rm -Rf $tmpdir
|
||||
|
Loading…
x
Reference in New Issue
Block a user