hush: treat ${#?} as "length of $?"
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
64925384c9
commit
645c697372
43
shell/ash_test/ash-vars/param_expand_indicate_error.right
Normal file
43
shell/ash_test/ash-vars/param_expand_indicate_error.right
Normal file
@ -0,0 +1,43 @@
|
|||||||
|
SHELL: line 1: syntax error: bad substitution
|
||||||
|
1
|
||||||
|
0
|
||||||
|
====
|
||||||
|
_
|
||||||
|
SHELL: line 1: 1: parameter not set
|
||||||
|
SHELL: line 1: 1: parameter not set or null
|
||||||
|
SHELL: line 1: 1: message1
|
||||||
|
SHELL: line 1: 1: message1
|
||||||
|
SHELL: line 1: 1: unset!
|
||||||
|
SHELL: line 1: 1: null or unset!
|
||||||
|
====
|
||||||
|
_aaaa
|
||||||
|
_aaaa
|
||||||
|
_aaaa
|
||||||
|
_aaaa
|
||||||
|
_aaaa
|
||||||
|
_aaaa
|
||||||
|
_aaaa
|
||||||
|
====
|
||||||
|
_
|
||||||
|
SHELL: line 1: f: parameter not set
|
||||||
|
SHELL: line 1: f: parameter not set or null
|
||||||
|
SHELL: line 1: f: message3
|
||||||
|
SHELL: line 1: f: message3
|
||||||
|
SHELL: line 1: f: unset!
|
||||||
|
SHELL: line 1: f: null or unset!
|
||||||
|
====
|
||||||
|
_
|
||||||
|
_
|
||||||
|
SHELL: line 1: f: parameter not set or null
|
||||||
|
_
|
||||||
|
SHELL: line 1: f: message4
|
||||||
|
_
|
||||||
|
SHELL: line 1: f: null or unset!
|
||||||
|
====
|
||||||
|
_fff
|
||||||
|
_fff
|
||||||
|
_fff
|
||||||
|
_fff
|
||||||
|
_fff
|
||||||
|
_fff
|
||||||
|
_fff
|
61
shell/ash_test/ash-vars/param_expand_indicate_error.tests
Executable file
61
shell/ash_test/ash-vars/param_expand_indicate_error.tests
Executable file
@ -0,0 +1,61 @@
|
|||||||
|
# do all of these in subshells since it's supposed to error out
|
||||||
|
# (set argv0 to "SHELL" to avoid "/path/to/shell: blah" in error messages)
|
||||||
|
|
||||||
|
# first try some invalid patterns
|
||||||
|
#"$THIS_SH" -c 'echo ${?}' SHELL -- this is valid as it's the same as $?
|
||||||
|
"$THIS_SH" -c 'echo ${:?}' SHELL
|
||||||
|
|
||||||
|
# then some funky ones
|
||||||
|
# note: bash prints 1 - treats it as "length of $#"
|
||||||
|
"$THIS_SH" -c 'echo ${#?}' SHELL
|
||||||
|
# bash prints 0
|
||||||
|
"$THIS_SH" -c 'echo ${#:?}' SHELL
|
||||||
|
|
||||||
|
# now some valid ones
|
||||||
|
export msg_unset="unset!"
|
||||||
|
export msg_null_or_unset="null or unset!"
|
||||||
|
|
||||||
|
echo ====
|
||||||
|
"$THIS_SH" -c 'set --; echo _$1' SHELL
|
||||||
|
"$THIS_SH" -c 'set --; echo _${1?}' SHELL
|
||||||
|
"$THIS_SH" -c 'set --; echo _${1:?}' SHELL
|
||||||
|
"$THIS_SH" -c 'set --; echo _${1?message1}' SHELL
|
||||||
|
"$THIS_SH" -c 'set --; echo _${1:?message1}' SHELL
|
||||||
|
"$THIS_SH" -c 'set --; echo _${1?$msg_unset}' SHELL
|
||||||
|
"$THIS_SH" -c 'set --; echo _${1:?$msg_null_or_unset}' SHELL
|
||||||
|
|
||||||
|
echo ====
|
||||||
|
"$THIS_SH" -c 'set -- aaaa; echo _$1' SHELL
|
||||||
|
"$THIS_SH" -c 'set -- aaaa; echo _${1?}' SHELL
|
||||||
|
"$THIS_SH" -c 'set -- aaaa; echo _${1:?}' SHELL
|
||||||
|
"$THIS_SH" -c 'set -- aaaa; echo _${1?word}' SHELL
|
||||||
|
"$THIS_SH" -c 'set -- aaaa; echo _${1:?word}' SHELL
|
||||||
|
"$THIS_SH" -c 'set -- aaaa; echo _${1?$msg_unset}' SHELL
|
||||||
|
"$THIS_SH" -c 'set -- aaaa; echo _${1:?$msg_null_or_unset}' SHELL
|
||||||
|
|
||||||
|
echo ====
|
||||||
|
"$THIS_SH" -c 'unset f; echo _$f' SHELL
|
||||||
|
"$THIS_SH" -c 'unset f; echo _${f?}' SHELL
|
||||||
|
"$THIS_SH" -c 'unset f; echo _${f:?}' SHELL
|
||||||
|
"$THIS_SH" -c 'unset f; echo _${f?message3}' SHELL
|
||||||
|
"$THIS_SH" -c 'unset f; echo _${f:?message3}' SHELL
|
||||||
|
"$THIS_SH" -c 'unset f; echo _${f?$msg_unset}' SHELL
|
||||||
|
"$THIS_SH" -c 'unset f; echo _${f:?$msg_null_or_unset}' SHELL
|
||||||
|
|
||||||
|
echo ====
|
||||||
|
"$THIS_SH" -c 'f=; echo _$f' SHELL
|
||||||
|
"$THIS_SH" -c 'f=; echo _${f?}' SHELL
|
||||||
|
"$THIS_SH" -c 'f=; echo _${f:?}' SHELL
|
||||||
|
"$THIS_SH" -c 'f=; echo _${f?word}' SHELL
|
||||||
|
"$THIS_SH" -c 'f=; echo _${f:?message4}' SHELL
|
||||||
|
"$THIS_SH" -c 'f=; echo _${f?$msg_unset}' SHELL
|
||||||
|
"$THIS_SH" -c 'f=; echo _${f:?$msg_null_or_unset}' SHELL
|
||||||
|
|
||||||
|
echo ====
|
||||||
|
"$THIS_SH" -c 'f=fff; echo _$f' SHELL
|
||||||
|
"$THIS_SH" -c 'f=fff; echo _${f?}' SHELL
|
||||||
|
"$THIS_SH" -c 'f=fff; echo _${f:?}' SHELL
|
||||||
|
"$THIS_SH" -c 'f=fff; echo _${f?word}' SHELL
|
||||||
|
"$THIS_SH" -c 'f=fff; echo _${f:?word}' SHELL
|
||||||
|
"$THIS_SH" -c 'f=fff; echo _${f?$msg_unset}' SHELL
|
||||||
|
"$THIS_SH" -c 'f=fff; echo _${f:?$msg_null_or_unset}' SHELL
|
12
shell/hush.c
12
shell/hush.c
@ -5559,8 +5559,10 @@ static NOINLINE const char *expand_one_var(char **to_be_freed_pp, char *arg, cha
|
|||||||
first_char = arg[0] = arg0 & 0x7f;
|
first_char = arg[0] = arg0 & 0x7f;
|
||||||
exp_op = 0;
|
exp_op = 0;
|
||||||
|
|
||||||
if (first_char == '#' /* ${#... */
|
if (first_char == '#' && arg[1] /* ${#... but not ${#} */
|
||||||
&& arg[1] && !exp_saveptr /* not ${#} and not ${#<op_char>...} */
|
&& (!exp_saveptr /* and (not ${#<op_char>...} */
|
||||||
|
|| (arg[1] == '?' && arg[2] == '\0') /* or ${#?} - "len of $?") */
|
||||||
|
)
|
||||||
) {
|
) {
|
||||||
/* It must be length operator: ${#var} */
|
/* It must be length operator: ${#var} */
|
||||||
var++;
|
var++;
|
||||||
@ -5797,7 +5799,11 @@ static NOINLINE const char *expand_one_var(char **to_be_freed_pp, char *arg, cha
|
|||||||
/* mimic bash message */
|
/* mimic bash message */
|
||||||
die_if_script("%s: %s",
|
die_if_script("%s: %s",
|
||||||
var,
|
var,
|
||||||
exp_word[0] ? exp_word : "parameter null or not set"
|
exp_word[0]
|
||||||
|
? exp_word
|
||||||
|
: "parameter null or not set"
|
||||||
|
/* ash has more specific messages, a-la: */
|
||||||
|
/*: (exp_save == ':' ? "parameter null or not set" : "parameter not set")*/
|
||||||
);
|
);
|
||||||
//TODO: how interactive bash aborts expansion mid-command?
|
//TODO: how interactive bash aborts expansion mid-command?
|
||||||
} else {
|
} else {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
hush: syntax error: unterminated ${name}
|
hush: syntax error: unterminated ${name}
|
||||||
0
|
1
|
||||||
0
|
0
|
||||||
====
|
====
|
||||||
_
|
_
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
"$THIS_SH" -c 'echo ${:?}'
|
"$THIS_SH" -c 'echo ${:?}'
|
||||||
|
|
||||||
# then some funky ones
|
# then some funky ones
|
||||||
# note: bash prints 1 - treats it as "length of $#"? We print 0
|
# note: bash prints 1 - treats it as "length of $#"
|
||||||
"$THIS_SH" -c 'echo ${#?}'
|
"$THIS_SH" -c 'echo ${#?}'
|
||||||
# bash prints 0
|
# bash prints 0
|
||||||
"$THIS_SH" -c 'echo ${#:?}'
|
"$THIS_SH" -c 'echo ${#:?}'
|
||||||
|
Loading…
Reference in New Issue
Block a user