mirror of
https://github.com/SerenityOS/serenity.git
synced 2025-01-24 10:22:05 -05:00
Shell: Add support for special parameter that expands to return-code of last program executed
This commit is contained in:
parent
2bd181a14b
commit
91a609d945
2 changed files with 5 additions and 0 deletions
|
@ -14,6 +14,7 @@ struct GlobalState {
|
||||||
struct termios termios;
|
struct termios termios;
|
||||||
bool was_interrupted { false };
|
bool was_interrupted { false };
|
||||||
bool was_resized { false };
|
bool was_resized { false };
|
||||||
|
int last_return_code { 0 };
|
||||||
};
|
};
|
||||||
|
|
||||||
extern GlobalState g;
|
extern GlobalState g;
|
||||||
|
|
|
@ -307,6 +307,8 @@ static Vector<String> expand_parameters(const StringView& param)
|
||||||
return { param };
|
return { param };
|
||||||
|
|
||||||
String variable_name = String(param.substring_view(1, param.length() - 1));
|
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());
|
char* env_value = getenv(variable_name.characters());
|
||||||
if (env_value == nullptr)
|
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?
|
// 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?
|
// Is the terminal controlling pgrp really still the PGID of the dead process?
|
||||||
tcsetpgrp(0, getpid());
|
tcsetpgrp(0, getpid());
|
||||||
|
|
Loading…
Add table
Reference in a new issue