From 0fa540180097e51230c9a6323a954bf8e7b77581 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Tue, 15 Aug 2023 09:17:46 +0300 Subject: [PATCH] Shell: $? returns last return value --- userspace/Shell/main.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/userspace/Shell/main.cpp b/userspace/Shell/main.cpp index cf43a842..07b46b0c 100644 --- a/userspace/Shell/main.cpp +++ b/userspace/Shell/main.cpp @@ -19,6 +19,7 @@ struct termios old_termios, new_termios; extern char** environ; static const char* argv0 = nullptr; +static int last_return = 0; BAN::Vector parse_command(BAN::StringView); @@ -28,7 +29,12 @@ BAN::Optional parse_dollar(BAN::StringView command, size_t& i) if (++i >= command.size()) return "$"sv; - + + if (command[i] == '?') + { + i++; + return BAN::String::formatted("{}", last_return); + } if (isalnum(command[i])) { size_t len = 1; @@ -643,7 +649,7 @@ int main(int argc, char** argv) { tcsetattr(0, TCSANOW, &old_termios); auto parsed_arguments = parse_command(buffers[index]); - execute_command(parsed_arguments); + last_return = execute_command(parsed_arguments); tcsetattr(0, TCSANOW, &new_termios); MUST(history.push_back(buffers[index])); buffers = history;