diff --git a/src/lib/shell/mod.rs b/src/lib/shell/mod.rs
index 326f8ce33107271527da01cdeb7e2c0f930b57c9..3192ee9ebdca5f5b412b1ec805d4923b4df9a556 100644
--- a/src/lib/shell/mod.rs
+++ b/src/lib/shell/mod.rs
@@ -434,7 +434,9 @@ impl<'a> Expander for Shell {
     /// Expand a string variable given if its quoted / unquoted
     fn string(&self, name: &str, quoted: bool) -> Option<types::Str> {
         use ascii_helpers::AsciiReplace;
-        if quoted {
+        if name == "?" {
+            Some(types::Str::from(self.previous_status.to_string()))
+        } else if quoted {
             self.get::<types::Str>(name)
         } else {
             self.get::<types::Str>(name)