diff --git a/utils/mxsh.cpp b/utils/mxsh.cpp index ee0c0ce7..2e41878d 100644 --- a/utils/mxsh.cpp +++ b/utils/mxsh.cpp @@ -139,7 +139,7 @@ readcmd: goto readcmd; } - int status = internalresult; + status = internalresult; if ( !internal && waitpid(childpid, &status, 0) < 0 ) { perror("waitpid"); @@ -182,6 +182,10 @@ readcmd: } } + char statusstr[32]; + sprintf(statusstr, "%i", status); + setenv("?", statusstr, 1); + for ( char** argp = argv; *argp; argp++ ) { char* arg = *argp; @@ -248,10 +252,6 @@ void command() if ( command[0] == '\0' ) { return; } - if ( strcmp(command, "$?") == 0 ) { printf("%u\n", status); status = 0; return; } - if ( strcmp(command, "$$") == 0 ) { printf("%u\n", getpid()); status = 0; return; } - if ( strcmp(command, "$PPID") == 0 ) { printf("%u\n", getppid()); status = 0; return; } - if ( strchr(command, '=') ) { if ( putenv(strdup(command)) ) { perror("putenv"); status = 1; return; } @@ -290,6 +290,14 @@ void command() int main(int argc, char* argv[]) { + char pidstr[32]; + char ppidstr[32]; + sprintf(pidstr, "%i", getpid()); + sprintf(ppidstr, "%i", getppid()); + setenv("SHELL", argv[0], 1); + setenv("$", pidstr, 1); + setenv("PPID", ppidstr, 1); + setenv("?", "0", 1); while ( true ) { command(); } }