hush: fix handling of $_ (so far it's an ordinary variable, no special meaning)
function old new delta parse_dollar 820 779 -41 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
a497231f53
commit
0ca3198f93
31
shell/hush.c
31
shell/hush.c
@ -4520,9 +4520,10 @@ static int parse_dollar(o_string *as_string,
|
|||||||
|
|
||||||
debug_printf_parse("parse_dollar entered: ch='%c'\n", ch);
|
debug_printf_parse("parse_dollar entered: ch='%c'\n", ch);
|
||||||
if (isalpha(ch)) {
|
if (isalpha(ch)) {
|
||||||
|
make_var:
|
||||||
ch = i_getch(input);
|
ch = i_getch(input);
|
||||||
nommu_addchr(as_string, ch);
|
nommu_addchr(as_string, ch);
|
||||||
make_var:
|
/*make_var1:*/
|
||||||
o_addchr(dest, SPECIAL_VAR_SYMBOL);
|
o_addchr(dest, SPECIAL_VAR_SYMBOL);
|
||||||
while (1) {
|
while (1) {
|
||||||
debug_printf_parse(": '%c'\n", ch);
|
debug_printf_parse(": '%c'\n", ch);
|
||||||
@ -4715,19 +4716,22 @@ static int parse_dollar(o_string *as_string,
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
case '_':
|
case '_':
|
||||||
ch = i_getch(input);
|
goto make_var;
|
||||||
nommu_addchr(as_string, ch);
|
#if 0
|
||||||
ch = i_peek_and_eat_bkslash_nl(input);
|
|
||||||
if (isalnum(ch)) { /* it's $_name or $_123 */
|
|
||||||
ch = '_';
|
|
||||||
goto make_var;
|
|
||||||
}
|
|
||||||
/* else: it's $_ */
|
|
||||||
/* TODO: $_ and $-: */
|
/* TODO: $_ and $-: */
|
||||||
/* $_ Shell or shell script name; or last argument of last command
|
/* $_ Shell or shell script name; or last argument of last command
|
||||||
* (if last command wasn't a pipe; if it was, bash sets $_ to "");
|
* (if last command wasn't a pipe; if it was, bash sets $_ to "");
|
||||||
* but in command's env, set to full pathname used to invoke it */
|
* but in command's env, set to full pathname used to invoke it */
|
||||||
/* $- Option flags set by set builtin or shell options (-i etc) */
|
/* $- Option flags set by set builtin or shell options (-i etc) */
|
||||||
|
ch = i_getch(input);
|
||||||
|
nommu_addchr(as_string, ch);
|
||||||
|
ch = i_peek_and_eat_bkslash_nl(input);
|
||||||
|
if (isalnum(ch)) { /* it's $_name or $_123 */
|
||||||
|
ch = '_';
|
||||||
|
goto make_var1;
|
||||||
|
}
|
||||||
|
/* else: it's $_ */
|
||||||
|
#endif
|
||||||
default:
|
default:
|
||||||
o_addQchr(dest, '$');
|
o_addQchr(dest, '$');
|
||||||
}
|
}
|
||||||
@ -5669,9 +5673,9 @@ static char *replace_pattern(char *val, const char *pattern, const char *repl, c
|
|||||||
*/
|
*/
|
||||||
static NOINLINE const char *expand_one_var(char **to_be_freed_pp, char *arg, char **pp)
|
static NOINLINE const char *expand_one_var(char **to_be_freed_pp, char *arg, char **pp)
|
||||||
{
|
{
|
||||||
const char *val = NULL;
|
const char *val;
|
||||||
char *to_be_freed = NULL;
|
char *to_be_freed;
|
||||||
char *p = *pp;
|
char *p;
|
||||||
char *var;
|
char *var;
|
||||||
char first_char;
|
char first_char;
|
||||||
char exp_op;
|
char exp_op;
|
||||||
@ -5680,6 +5684,9 @@ static NOINLINE const char *expand_one_var(char **to_be_freed_pp, char *arg, cha
|
|||||||
char *exp_word = exp_word; /* for compiler */
|
char *exp_word = exp_word; /* for compiler */
|
||||||
char arg0;
|
char arg0;
|
||||||
|
|
||||||
|
val = NULL;
|
||||||
|
to_be_freed = NULL;
|
||||||
|
p = *pp;
|
||||||
*p = '\0'; /* replace trailing SPECIAL_VAR_SYMBOL */
|
*p = '\0'; /* replace trailing SPECIAL_VAR_SYMBOL */
|
||||||
var = arg;
|
var = arg;
|
||||||
exp_saveptr = arg[1] ? strchr(VAR_ENCODED_SUBST_OPS, arg[1]) : NULL;
|
exp_saveptr = arg[1] ? strchr(VAR_ENCODED_SUBST_OPS, arg[1]) : NULL;
|
||||||
|
Loading…
Reference in New Issue
Block a user