diff options
Diffstat (limited to 'shell/lash.c')
-rw-r--r-- | shell/lash.c | 29 |
1 files changed, 15 insertions, 14 deletions
diff --git a/shell/lash.c b/shell/lash.c index ce1ce7f6a..781dfdb5a 100644 --- a/shell/lash.c +++ b/shell/lash.c | |||
@@ -157,8 +157,8 @@ static int shell_context; /* Type prompt trigger (PS1 or PS2) */ | |||
157 | static char *cwd; | 157 | static char *cwd; |
158 | static char *local_pending_command; | 158 | static char *local_pending_command; |
159 | static struct jobset job_list = { NULL, NULL }; | 159 | static struct jobset job_list = { NULL, NULL }; |
160 | static int argc; | 160 | static int global_argc; |
161 | static char **argv; | 161 | static char **global_argv; |
162 | static llist_t *close_me_list; | 162 | static llist_t *close_me_list; |
163 | static int last_return_code; | 163 | static int last_return_code; |
164 | static int last_bg_pid; | 164 | static int last_bg_pid; |
@@ -810,16 +810,16 @@ static int expand_arguments(char *command) | |||
810 | var = itoa(getpid()); | 810 | var = itoa(getpid()); |
811 | break; | 811 | break; |
812 | case '#': | 812 | case '#': |
813 | var = itoa(argc-1); | 813 | var = itoa(global_argc - 1); |
814 | break; | 814 | break; |
815 | case '0':case '1':case '2':case '3':case '4': | 815 | case '0':case '1':case '2':case '3':case '4': |
816 | case '5':case '6':case '7':case '8':case '9': | 816 | case '5':case '6':case '7':case '8':case '9': |
817 | { | 817 | { |
818 | int ixx = *(dst+1)-48+1; | 818 | int ixx = *(dst+1)-48+1; |
819 | if (ixx >= argc) { | 819 | if (ixx >= global_argc) { |
820 | var = '\0'; | 820 | var = '\0'; |
821 | } else { | 821 | } else { |
822 | var = argv[ixx]; | 822 | var = global_argv[ixx]; |
823 | } | 823 | } |
824 | } | 824 | } |
825 | break; | 825 | break; |
@@ -1492,12 +1492,13 @@ static inline void setup_job_control(void) | |||
1492 | #endif | 1492 | #endif |
1493 | 1493 | ||
1494 | int lash_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; | 1494 | int lash_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE; |
1495 | int lash_main(int argc_l, char **argv_l) | 1495 | int lash_main(int argc, char **argv) |
1496 | { | 1496 | { |
1497 | unsigned opt; | 1497 | unsigned opt; |
1498 | FILE *input = stdin; | 1498 | FILE *input = stdin; |
1499 | argc = argc_l; | 1499 | |
1500 | argv = argv_l; | 1500 | global_argc = argc; |
1501 | global_argv = argv; | ||
1501 | 1502 | ||
1502 | #if ENABLE_FEATURE_EDITING | 1503 | #if ENABLE_FEATURE_EDITING |
1503 | line_input_state = new_line_input_t(FOR_SHELL); | 1504 | line_input_state = new_line_input_t(FOR_SHELL); |
@@ -1510,7 +1511,7 @@ int lash_main(int argc_l, char **argv_l) | |||
1510 | job_list.fg = NULL; | 1511 | job_list.fg = NULL; |
1511 | last_return_code = 1; | 1512 | last_return_code = 1; |
1512 | 1513 | ||
1513 | if (argv[0] && argv[0][0] == '-') { | 1514 | if (global_argv[0] && global_argv[0][0] == '-') { |
1514 | FILE *prof_input; | 1515 | FILE *prof_input; |
1515 | prof_input = fopen("/etc/profile", "r"); | 1516 | prof_input = fopen("/etc/profile", "r"); |
1516 | if (prof_input) { | 1517 | if (prof_input) { |
@@ -1522,13 +1523,13 @@ int lash_main(int argc_l, char **argv_l) | |||
1522 | } | 1523 | } |
1523 | } | 1524 | } |
1524 | 1525 | ||
1525 | opt = getopt32(argv_l, "+ic:", &local_pending_command); | 1526 | opt = getopt32(argv, "+ic:", &local_pending_command); |
1526 | #define LASH_OPT_i (1<<0) | 1527 | #define LASH_OPT_i (1<<0) |
1527 | #define LASH_OPT_c (1<<1) | 1528 | #define LASH_OPT_c (1<<1) |
1528 | if (opt & LASH_OPT_c) { | 1529 | if (opt & LASH_OPT_c) { |
1529 | input = NULL; | 1530 | input = NULL; |
1530 | optind++; | 1531 | optind++; |
1531 | argv += optind; | 1532 | global_argv += optind; |
1532 | } | 1533 | } |
1533 | /* A shell is interactive if the `-i' flag was given, or if all of | 1534 | /* A shell is interactive if the `-i' flag was given, or if all of |
1534 | * the following conditions are met: | 1535 | * the following conditions are met: |
@@ -1537,7 +1538,7 @@ int lash_main(int argc_l, char **argv_l) | |||
1537 | * standard input is a terminal | 1538 | * standard input is a terminal |
1538 | * standard output is a terminal | 1539 | * standard output is a terminal |
1539 | * Refer to Posix.2, the description of the `sh' utility. */ | 1540 | * Refer to Posix.2, the description of the `sh' utility. */ |
1540 | if (argv[optind] == NULL && input == stdin | 1541 | if (global_argv[optind] == NULL && input == stdin |
1541 | && isatty(STDIN_FILENO) && isatty(STDOUT_FILENO) | 1542 | && isatty(STDIN_FILENO) && isatty(STDOUT_FILENO) |
1542 | ) { | 1543 | ) { |
1543 | opt |= LASH_OPT_i; | 1544 | opt |= LASH_OPT_i; |
@@ -1550,9 +1551,9 @@ int lash_main(int argc_l, char **argv_l) | |||
1550 | "Enter 'help' for a list of built-in commands.\n\n", | 1551 | "Enter 'help' for a list of built-in commands.\n\n", |
1551 | bb_banner); | 1552 | bb_banner); |
1552 | } | 1553 | } |
1553 | } else if (!local_pending_command && argv[optind]) { | 1554 | } else if (!local_pending_command && global_argv[optind]) { |
1554 | //printf( "optind=%d argv[optind]='%s'\n", optind, argv[optind]); | 1555 | //printf( "optind=%d argv[optind]='%s'\n", optind, argv[optind]); |
1555 | input = xfopen(argv[optind], "r"); | 1556 | input = xfopen(global_argv[optind], "r"); |
1556 | /* be lazy, never mark this closed */ | 1557 | /* be lazy, never mark this closed */ |
1557 | llist_add_to(&close_me_list, (void *)(long)fileno(input)); | 1558 | llist_add_to(&close_me_list, (void *)(long)fileno(input)); |
1558 | } | 1559 | } |