[PATCH] hush: fix last_return_code when PROMPT_COMMAND is used
Sascha Hauer
s.hauer at pengutronix.de
Wed Sep 17 06:36:24 PDT 2025
Wenn PROMPT_COMMAND is used then a "echo $?" shows the result of the
PROMPT_COMMAND instead of the result of the last command. Fix this by
restoring the previous value after PROMPT_COMMAND has been executed.
Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
---
common/hush.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/common/hush.c b/common/hush.c
index 8515e77338..ec3c0cd913 100644
--- a/common/hush.c
+++ b/common/hush.c
@@ -433,9 +433,13 @@ static char *getprompt(void)
prompt_command = getenv("PROMPT_COMMAND");
if (prompt_command) {
+ unsigned int lr = last_return_code;
+
initialize_context(&ctx);
parse_string_outer(&ctx, prompt_command, FLAG_PARSE_SEMICOLON);
release_context(&ctx);
+
+ last_return_code = lr;
}
ps1 = getenv("PS1");
--
2.47.3
More information about the barebox
mailing list