From 33a3f0e1345154954045278772f7ce88f22f1444 Mon Sep 17 00:00:00 2001 From: Ali Mohammad Pur Date: Thu, 31 Aug 2023 02:36:38 +0330 Subject: [PATCH] Shell: Implement close redirections in POSIX mode Fixes #20631. --- Userland/Shell/PosixParser.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Userland/Shell/PosixParser.cpp b/Userland/Shell/PosixParser.cpp index 4b1936bace..00646cab46 100644 --- a/Userland/Shell/PosixParser.cpp +++ b/Userland/Shell/PosixParser.cpp @@ -2103,7 +2103,14 @@ ErrorOr> Parser::parse_io_file(AST::Position start_position, O auto is_less = io_operator == Token::Type::LessAnd; auto source_fd = fd.value_or(is_less ? 0 : 1); if (word->is_bareword()) { - auto maybe_target_fd = static_ptr_cast(word)->text().bytes_as_string_view().to_int(); + auto text = static_ptr_cast(word)->text(); + if (!is_less && text == "-"sv) { + return make_ref_counted( + position, + source_fd); + } + + auto maybe_target_fd = text.bytes_as_string_view().to_int(); if (maybe_target_fd.has_value()) { auto target_fd = maybe_target_fd.release_value(); if (is_less)