1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-31 07:38:10 +00:00

Shell: Add support for special parameter that expands to return-code of last program executed

This commit is contained in:
MinusGix 2019-09-08 20:00:35 -05:00 committed by Andreas Kling
parent 2bd181a14b
commit 91a609d945
2 changed files with 5 additions and 0 deletions

View file

@ -307,6 +307,8 @@ static Vector<String> expand_parameters(const StringView& param)
return { param };
String variable_name = String(param.substring_view(1, param.length() - 1));
if (variable_name == "?")
return { String::number(g.last_return_code) };
char* env_value = getenv(variable_name.characters());
if (env_value == nullptr)
@ -546,6 +548,8 @@ static int run_command(const String& cmd)
}
}
g.last_return_code = return_value;
// FIXME: Should I really have to tcsetpgrp() after my child has exited?
// Is the terminal controlling pgrp really still the PGID of the dead process?
tcsetpgrp(0, getpid());