Shell: Make builtin exit command read exit value from argument

Shell used to unconditionally return with exit code of 0
This commit is contained in:
Bananymous 2024-10-06 01:24:34 +03:00
parent d542cd811d
commit 4b13055125
1 changed files with 8 additions and 1 deletions

View File

@ -389,7 +389,14 @@ static BAN::Optional<int> execute_builtin(const SingleCommand& command, int fd_i
} }
else if (command.arguments.front() == "exit"_sv) 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) else if (command.arguments.front() == "export"_sv)
{ {