beg = bb_strtou(exp_word, &end, 0);
//bb_error_msg("beg:'%s'=%u end:'%s'", exp_word, beg, end);
if (*end == ':') {
- len = bb_strtou(end + 1, &end, 0);
+ if (end[1] != '\0') /* not ${var:NUM:} */
+ len = bb_strtou(end + 1, &end, 0);
+ else {
+ len = 0;
+ end++;
+ }
//bb_error_msg("len:%u end:'%s'", len, end);
}
if (*end == '\0') {
//bb_error_msg("from val:'%s'", val);
- if (!val || beg >= strlen(val))
+ if (len == 0 || !val || beg >= strlen(val))
val = "";
else
val = dyn_val = xstrndup(val + beg, len);
#endif
{
die_if_script("malformed ${%s...}", var);
+ val = "";
}
} else { /* one of "-=+?" */
/* Standard-mandated substitution ops:
"$THIS_SH" -c 'set --; echo "1:1 =|${1:1}|"'
"$THIS_SH" -c 'set --; echo "1:1:2=|${1:1:2}|"'
"$THIS_SH" -c 'set --; echo "1::2 =|${1::2}|"'
+"$THIS_SH" -c 'set --; echo "1:1: =|${1:1:}|"'
+"$THIS_SH" -c 'set --; echo "1:: =|${1::}|"'
"$THIS_SH" -c 'set -- 0123; echo "1 =|${1}|"'
"$THIS_SH" -c 'set -- 0123; echo "1:1 =|${1:1}|"'
"$THIS_SH" -c 'set -- 0123; echo "1:1:2=|${1:1:2}|"'
"$THIS_SH" -c 'set -- 0123; echo "1::2 =|${1::2}|"'
+"$THIS_SH" -c 'set -- 0123; echo "1:1: =|${1:1:}|"'
+"$THIS_SH" -c 'set -- 0123; echo "1:: =|${1::}|"'
"$THIS_SH" -c 'unset f; echo "f =|$f|"'
"$THIS_SH" -c 'unset f; echo "f:1 =|${f:1}|"'
"$THIS_SH" -c 'unset f; echo "f:1:2=|${f:1:2}|"'
"$THIS_SH" -c 'unset f; echo "f::2 =|${f::2}|"'
+"$THIS_SH" -c 'unset f; echo "f:1: =|${f:1:}|"'
+"$THIS_SH" -c 'unset f; echo "f:: =|${f::}|"'
"$THIS_SH" -c 'f=; echo "f =|$f|"'
"$THIS_SH" -c 'f=; echo "f:1 =|${f:1}|"'
"$THIS_SH" -c 'f=; echo "f:1:2=|${f:1:2}|"'
"$THIS_SH" -c 'f=; echo "f::2 =|${f::2}|"'
+"$THIS_SH" -c 'f=; echo "f:1: =|${f:1:}|"'
+"$THIS_SH" -c 'f=; echo "f:: =|${f::}|"'
"$THIS_SH" -c 'f=a; echo "f =|$f|"'
"$THIS_SH" -c 'f=a; echo "f:1 =|${f:1}|"'
"$THIS_SH" -c 'f=a; echo "f:1:2=|${f:1:2}|"'
"$THIS_SH" -c 'f=a; echo "f::2 =|${f::2}|"'
+"$THIS_SH" -c 'f=a; echo "f:1: =|${f:1:}|"'
+"$THIS_SH" -c 'f=a; echo "f:: =|${f::}|"'
"$THIS_SH" -c 'f=0123456789; echo "f =|$f|"'
"$THIS_SH" -c 'f=0123456789; echo "f:1 =|${f:1}|"'
"$THIS_SH" -c 'f=0123456789; echo "f:1:2=|${f:1:2}|"'
"$THIS_SH" -c 'f=0123456789; echo "f::2 =|${f::2}|"'
+"$THIS_SH" -c 'f=0123456789; echo "f:1: =|${f:1:}|"'
+"$THIS_SH" -c 'f=0123456789; echo "f:: =|${f::}|"'