1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-25 12:37:44 +00:00

Shell: Implement the return POSIX builtin

This is also available in the regular shell mode, as it's a generally
useful builtin to have.
This commit is contained in:
Ali Mohammad Pur 2023-10-16 21:21:22 +03:30 committed by Andrew Kaster
parent 2d1c5dbfcb
commit a8c7448ccb
4 changed files with 25 additions and 1 deletions

View file

@ -268,6 +268,23 @@ ErrorOr<int> Shell::builtin_continue(Main::Arguments arguments)
return 0;
}
ErrorOr<int> Shell::builtin_return(Main::Arguments arguments)
{
int return_code = last_return_code.value_or(0);
Core::ArgsParser parser;
parser.add_positional_argument(return_code, "Return code to return to the parent shell", "return-code", Core::ArgsParser::Required::No);
parser.set_general_help("Return from a function or source file");
if (!parser.parse(arguments, Core::ArgsParser::FailureBehavior::PrintUsage))
return 1;
last_return_code = return_code & 0xff;
raise_error(ShellError::InternalControlFlowReturn, "POSIX return");
return 0;
}
ErrorOr<int> Shell::builtin_bg(Main::Arguments arguments)
{
int job_id = -1;