From ac6487932bf9e38a5118dfc95febd37a148b7eae Mon Sep 17 00:00:00 2001 From: Giles Atkinson <“gatk555@gmail.com”> Date: Tue, 23 May 2023 17:28:16 +0100 Subject: [PATCH] Make the returned status of the "shell" command available as interpreter variable "shellstatus". Also change the default shell to /bin/sh as csh is now rare. --- src/frontend/com_shell.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/frontend/com_shell.c b/src/frontend/com_shell.c index 96e60417f..a2a73d098 100644 --- a/src/frontend/com_shell.c +++ b/src/frontend/com_shell.c @@ -14,13 +14,14 @@ #ifdef _WIN32 #define SHELL "cmd /k" #else -#define SHELL "/bin/csh" +#define SHELL "/bin/sh" #endif /* Fork a shell. */ void com_shell(wordlist *wl) { + int status; char *shell = NULL; shell = getenv("SHELL"); @@ -61,16 +62,20 @@ com_shell(wordlist *wl) /* Easier to forget about changing the io descriptors. */ if (wl) { char * const com = wl_flatten(wl); - if (system(com) == -1) { + + status = system(com); + if (status == -1) { (void) fprintf(cp_err, "Unable to execute \"%s\".\n", com); } txfree(com); } else { - if (system(shell) == -1) { + status = system(shell); + if (status == -1) { (void) fprintf(cp_err, "Unable to execute \"%s\".\n", shell); } } + cp_vset("shellstatus", CP_NUM, &status); #endif } /* end of function com_shell */