From 4b13055125436fd89296c9d8e03452ce23e64374 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Sun, 6 Oct 2024 01:24:34 +0300 Subject: [PATCH] Shell: Make builtin exit command read exit value from argument Shell used to unconditionally return with exit code of 0 --- userspace/programs/Shell/main.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/userspace/programs/Shell/main.cpp b/userspace/programs/Shell/main.cpp index fbe7208153..90abee777c 100644 --- a/userspace/programs/Shell/main.cpp +++ b/userspace/programs/Shell/main.cpp @@ -389,7 +389,14 @@ static BAN::Optional execute_builtin(const SingleCommand& command, int fd_i } else if (command.arguments.front() == "exit"_sv) { - exit(0); + int exit_code = 0; + if (command.arguments.size() > 1) + { + auto exit_string = command.arguments[1].sv(); + for (size_t i = 0; i < exit_string.size() && isdigit(exit_string[i]); i++) + exit_code = (exit_code * 10) + (exit_string[i] - '0'); + } + exit(exit_code); } else if (command.arguments.front() == "export"_sv) {