From fbf91f41e7ae91ab559c1693ed3428b6b405a9f2 Mon Sep 17 00:00:00 2001 From: sin-ack Date: Sat, 16 Jul 2022 23:09:03 +0000 Subject: [PATCH] Shell: Add the |& construct for piping stderr along with stdout When |& is typed, stderr will be piped to stdout before the actual piping happens. This behaves basically like a 2>&1 | (and the underlying implementation transforms it to that anyway). --- Userland/Shell/Parser.cpp | 12 ++++++++++++ Userland/Shell/Parser.h | 4 ++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Userland/Shell/Parser.cpp b/Userland/Shell/Parser.cpp index 49b3a27fe3..b6eb1d8444 100644 --- a/Userland/Shell/Parser.cpp +++ b/Userland/Shell/Parser.cpp @@ -510,6 +510,18 @@ RefPtr Parser::parse_pipe_sequence() auto before_pipe = save_offset(); consume(); + auto also_pipe_stderr = peek() == '&'; + if (also_pipe_stderr) { + consume(); + + RefPtr redirection; + { + auto redirection_start = push_start(); + redirection = create(STDERR_FILENO, STDOUT_FILENO); + } + + left = create(left.release_nonnull(), redirection.release_nonnull()); + } if (auto pipe_seq = parse_pipe_sequence()) { return create(left.release_nonnull(), pipe_seq.release_nonnull()); // Pipe diff --git a/Userland/Shell/Parser.h b/Userland/Shell/Parser.h index 41a2a333fe..802489d9b0 100644 --- a/Userland/Shell/Parser.h +++ b/Userland/Shell/Parser.h @@ -200,9 +200,9 @@ heredoc_entries :: { .*? (heredoc_entry) '\n' } [each heredoc_entries] variable_decls :: identifier '=' expression (' '+ variable_decls)? ' '* | identifier '=' '(' pipe_sequence ')' (' '+ variable_decls)? ' '* -pipe_sequence :: command '|' pipe_sequence +pipe_sequence :: command '|' '&'? pipe_sequence | command - | control_structure '|' pipe_sequence + | control_structure '|' '&'? pipe_sequence | control_structure control_structure[c] :: for_expr