diff options
-rw-r--r-- | shell/hush.c | 31 |
1 files changed, 26 insertions, 5 deletions
diff --git a/shell/hush.c b/shell/hush.c index 2b9abbdfd..9dd893aa6 100644 --- a/shell/hush.c +++ b/shell/hush.c | |||
@@ -466,9 +466,9 @@ | |||
466 | 466 | ||
467 | #define JOB_STATUS_FORMAT "[%u] %-22s %.40s\n" | 467 | #define JOB_STATUS_FORMAT "[%u] %-22s %.40s\n" |
468 | 468 | ||
469 | #define _SPECIAL_VARS_STR "_*@$!?#" | 469 | #define _SPECIAL_VARS_STR "_*@$!?#-" |
470 | #define SPECIAL_VARS_STR ("_*@$!?#" + 1) | 470 | #define SPECIAL_VARS_STR ("_*@$!?#-" + 1) |
471 | #define NUMERIC_SPECVARS_STR ("_*@$!?#" + 3) | 471 | #define NUMERIC_SPECVARS_STR ("_*@$!?#-" + 3) |
472 | #if BASH_PATTERN_SUBST | 472 | #if BASH_PATTERN_SUBST |
473 | /* Support / and // replace ops */ | 473 | /* Support / and // replace ops */ |
474 | /* Note that // is stored as \ in "encoded" string representation */ | 474 | /* Note that // is stored as \ in "encoded" string representation */ |
@@ -1008,6 +1008,7 @@ struct globals { | |||
1008 | int debug_indent; | 1008 | int debug_indent; |
1009 | #endif | 1009 | #endif |
1010 | struct sigaction sa; | 1010 | struct sigaction sa; |
1011 | char optstring_buf[sizeof("eix")]; | ||
1011 | #if BASH_EPOCH_VARS | 1012 | #if BASH_EPOCH_VARS |
1012 | char epoch_buf[sizeof("%lu.nnnnnn") + sizeof(long)*3]; | 1013 | char epoch_buf[sizeof("%lu.nnnnnn") + sizeof(long)*3]; |
1013 | #endif | 1014 | #endif |
@@ -4888,6 +4889,7 @@ static int parse_dollar(o_string *as_string, | |||
4888 | case '#': /* number of args */ | 4889 | case '#': /* number of args */ |
4889 | case '*': /* args */ | 4890 | case '*': /* args */ |
4890 | case '@': /* args */ | 4891 | case '@': /* args */ |
4892 | case '-': /* $- option flags set by set builtin or shell options (-i etc) */ | ||
4891 | goto make_one_char_var; | 4893 | goto make_one_char_var; |
4892 | case '{': { | 4894 | case '{': { |
4893 | char len_single_ch; | 4895 | char len_single_ch; |
@@ -5062,11 +5064,10 @@ static int parse_dollar(o_string *as_string, | |||
5062 | case '_': | 5064 | case '_': |
5063 | goto make_var; | 5065 | goto make_var; |
5064 | #if 0 | 5066 | #if 0 |
5065 | /* TODO: $_ and $-: */ | 5067 | /* TODO: $_: */ |
5066 | /* $_ Shell or shell script name; or last argument of last command | 5068 | /* $_ Shell or shell script name; or last argument of last command |
5067 | * (if last command wasn't a pipe; if it was, bash sets $_ to ""); | 5069 | * (if last command wasn't a pipe; if it was, bash sets $_ to ""); |
5068 | * but in command's env, set to full pathname used to invoke it */ | 5070 | * but in command's env, set to full pathname used to invoke it */ |
5069 | /* $- Option flags set by set builtin or shell options (-i etc) */ | ||
5070 | ch = i_getch(input); | 5071 | ch = i_getch(input); |
5071 | nommu_addchr(as_string, ch); | 5072 | nommu_addchr(as_string, ch); |
5072 | ch = i_peek_and_eat_bkslash_nl(input); | 5073 | ch = i_peek_and_eat_bkslash_nl(input); |
@@ -6397,6 +6398,23 @@ static NOINLINE int expand_one_var(o_string *output, int n, | |||
6397 | case '#': /* argc */ | 6398 | case '#': /* argc */ |
6398 | val = utoa(G.global_argc ? G.global_argc-1 : 0); | 6399 | val = utoa(G.global_argc ? G.global_argc-1 : 0); |
6399 | break; | 6400 | break; |
6401 | case '-': { /* active options */ | ||
6402 | /* Check set_mode() to see what option chars we support */ | ||
6403 | char *cp; | ||
6404 | val = cp = G.optstring_buf; | ||
6405 | if (G.o_opt[OPT_O_ERREXIT]) | ||
6406 | *cp++ = 'e'; | ||
6407 | if (G_interactive_fd) | ||
6408 | *cp++ = 'i'; | ||
6409 | if (G_x_mode) | ||
6410 | *cp++ = 'x'; | ||
6411 | /* If G.o_opt[OPT_O_NOEXEC] is true, | ||
6412 | * commands read but are not executed, | ||
6413 | * so $- can not execute too, 'n' is never seen in $-. | ||
6414 | */ | ||
6415 | *cp = '\0'; | ||
6416 | break; | ||
6417 | } | ||
6400 | default: | 6418 | default: |
6401 | val = get_local_var_value(var); | 6419 | val = get_local_var_value(var); |
6402 | } | 6420 | } |
@@ -9899,6 +9917,9 @@ int hush_main(int argc, char **argv) | |||
9899 | /* IFS is not inherited from the parent environment */ | 9917 | /* IFS is not inherited from the parent environment */ |
9900 | set_local_var_from_halves("IFS", defifs); | 9918 | set_local_var_from_halves("IFS", defifs); |
9901 | 9919 | ||
9920 | if (!get_local_var_value("PATH")) | ||
9921 | set_local_var_from_halves("PATH", bb_default_root_path); | ||
9922 | |||
9902 | /* PS1/PS2 are set later, if we determine that we are interactive */ | 9923 | /* PS1/PS2 are set later, if we determine that we are interactive */ |
9903 | 9924 | ||
9904 | /* bash also exports SHLVL and _, | 9925 | /* bash also exports SHLVL and _, |