On Wed, Nov 14, 2018 at 11:15:36PM +0100, Martijn Dekker wrote: > I encountered another bug, introduced by 3cd5386 and not fixed by v2 of this > patch: the presence of a length-counting expansion like ${#foo} in a string > causes the rest of the string to be discarded. > > $ src/dash -c 'foo=bar; echo "baz ${#foo} quux"' > baz 3 > $ src/dash -c 'foo=bar; echo baz\ ${#foo}\ quux' > baz 3 > > (expected outout: baz 3 quux) Thanks. This is an unrelated issue where we fail to eat the closing brace for $# expansion. This causes the outer argstr to termiante prematurely. ---8<--- expand: Eat closing brace for length parameter expansion When we are doing VSLENGTH expansion, the closing brace is currently not removed in evalvar. This causes the caller argstr to terminate prematurely as it would interpret the closing brace as one that belongs to a parameter expansion at the outer level. This patch fixes it. Reported-by: Martijn Dekker <martijn@xxxxxxxx> Fixes: 3cd538634f71 ("expand: Do not reprocess data when...") Signed-off-by: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx> diff --git a/src/expand.c b/src/expand.c index 856b7a9..af9cac9 100644 --- a/src/expand.c +++ b/src/expand.c @@ -745,6 +745,7 @@ again: varunset(p, var, 0, 0); if (subtype == VSLENGTH) { + p++; if (flag & EXP_DISCARD) return p; cvtnum(varlen > 0 ? varlen : 0, flag); -- Email: Herbert Xu <herbert@xxxxxxxxxxxxxxxxxxx> Home Page: http://gondor.apana.org.au/~herbert/ PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt