diff options
author | Eric Andersen | 2000-07-28 17:08:36 +0000 |
---|---|---|
committer | Eric Andersen | 2000-07-28 17:08:36 +0000 |
commit | 6a4c33c5c0e5d01c1280a0d77439cd9843eee55a (patch) | |
tree | 6baab056b5933e45a4b7fc326195114b647257c1 /shell | |
parent | 6150df320a8aa825d88d6382c51017f362f2aabe (diff) | |
download | busybox-6a4c33c5c0e5d01c1280a0d77439cd9843eee55a.zip busybox-6a4c33c5c0e5d01c1280a0d77439cd9843eee55a.tar.gz |
Clean up the nasty blunder I'd made of how different behaviors happen.
-Erik
Diffstat (limited to 'shell')
-rw-r--r-- | shell/lash.c | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/shell/lash.c b/shell/lash.c index 4727e9b..2cec66b 100644 --- a/shell/lash.c +++ b/shell/lash.c @@ -1383,7 +1383,7 @@ void free_memory(void) int shell_main(int argc_l, char **argv_l) { - int opt; + int opt, interactive=FALSE; FILE *input = stdin; argc = argc_l; argv = argv_l; @@ -1407,7 +1407,7 @@ int shell_main(int argc_l, char **argv_l) local_pending_command = realloc(local_pending_command, strlen(local_pending_command) + strlen(argv[optind])); if (local_pending_command==NULL) - fatalError("sh: command too long\n"); + fatalError("command too long\n"); } strcat(local_pending_command, argv[optind]); if ( (optind + 1) < argc) @@ -1419,29 +1419,31 @@ int shell_main(int argc_l, char **argv_l) showXtrace = TRUE; break; #endif + case 'i': + interactive = TRUE; + break; default: usage(shell_usage); } } - - - if (optind<1 && input == stdin) { + /* A shell is interactive if the `-i' flag was given, or if all of + * the following conditions are met: + * no -c command + * no arguments remaining or the -s flag given + * standard input is a terminal + * standard output is a terminal + * Refer to Posix.2, the description of the `sh' utility. */ + if (interactive==TRUE || ( argv[optind]==NULL && input==stdin && isatty(fileno(stdin)) && isatty(fileno(stdout)))) { + fprintf(stdout, "optind=%d argv[optind]='%s'\n", optind, argv[optind]); /* Looks like they want an interactive shell */ fprintf(stdout, "\n\nBusyBox v%s (%s) Built-in shell\n", BB_VER, BB_BT); fprintf(stdout, "Enter 'help' for a list of built-in commands.\n\n"); - } else if (1==(argc-optind)) { + } else if (local_pending_command==NULL) { + fprintf(stdout, "optind=%d argv[optind]='%s'\n", optind, argv[optind]); input = fopen(argv[optind], "r"); if (!input) { fatalError("%s: %s\n", argv[optind], strerror(errno)); } - } else { - char *oldpath, *newpath; - oldpath = getenv("PATH"); - newpath=(char*)xmalloc(strlen(oldpath)+12); - snprintf(newpath, strlen(oldpath)+9, "PATH=./:%s", oldpath); - putenv(newpath); - execvp(argv[optind], argv+optind); - fatalError("%s: %s\n", argv[optind], strerror(errno)); } /* initialize the cwd -- this is never freed...*/ |