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.
This commit is contained in:
Giles Atkinson 2023-05-23 17:28:16 +01:00 committed by Holger Vogt
parent 1c1a53bac8
commit ac6487932b
1 changed files with 8 additions and 3 deletions

View File

@ -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 */