summaryrefslogtreecommitdiff
path: root/Shell
diff options
context:
space:
mode:
authorMinusGix <MinusGix@gmail.com>2019-09-08 20:00:35 -0500
committerAndreas Kling <awesomekling@gmail.com>2019-09-10 14:51:55 +0200
commit91a609d945456565304b62862946131dd0dba100 (patch)
treeddafb2b62dfc5744960d215e3d05d4e170cea3c5 /Shell
parent2bd181a14bf627419d200c52b1a796063b26103b (diff)
downloadserenity-91a609d945456565304b62862946131dd0dba100.zip
Shell: Add support for special parameter that expands to return-code of last program executed
Diffstat (limited to 'Shell')
-rw-r--r--Shell/GlobalState.h1
-rw-r--r--Shell/main.cpp4
2 files changed, 5 insertions, 0 deletions
diff --git a/Shell/GlobalState.h b/Shell/GlobalState.h
index 1ca4a981e3..d87d798356 100644
--- a/Shell/GlobalState.h
+++ b/Shell/GlobalState.h
@@ -14,6 +14,7 @@ struct GlobalState {
struct termios termios;
bool was_interrupted { false };
bool was_resized { false };
+ int last_return_code { 0 };
};
extern GlobalState g;
diff --git a/Shell/main.cpp b/Shell/main.cpp
index 24d66ff38f..1ee0003b55 100644
--- a/Shell/main.cpp
+++ b/Shell/main.cpp
@@ -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());