Thanks for the patch!
---8<---
Vladimir N. Oleynik <[email protected]> wrote:
>
> dash have bug for ${#10} and etc: ignores 0... in name (without errors :)
>
> $ foo() { echo "length 10-th arg '${10}' is ${#10}"; }
> $ foo a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11
> length 10-th arg 'a10' is 2
>
> But need:
> length 10-th arg 'a10' is 3
>
> Micro patch attached
>
> --- parser.c~ 2021-02-04 00:51:34.000000000 +0400
> +++ parser.c 2021-02-05 12:42:43.616635640 +0400
> @@ -1274,7 +1274,7 @@
> do {
> STPUTC(c, out);
> c = pgetc_eatbnl();
> - } while (!subtype && is_digit(c));
> + } while ((!subtype || subtype == VSLENGTH) &&
> is_digit(c));
> } else if (c != '}') {
> int cc = c;
I would rather test against VSNORMAL.
Fixes: 7710a926b321 ("parser: Only accept single-digit parameter...")
Reported-by: Vladimir N. Oleynik <[email protected]>
Signed-off-by: Herbert Xu <[email protected]>
diff --git a/src/parser.c b/src/parser.c
index 3c80d17..834d2e3 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -1252,7 +1252,7 @@ varname:
do {
STPUTC(c, out);
c = pgetc_eatbnl();
- } while (!subtype && is_digit(c));
+ } while (subtype != VSNORMAL && is_digit(c));
} else if (c != '}') {
int cc = c;
--
Email: Herbert Xu <[email protected]>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt