From de6b75b187e92318b57865e2c404d2351474ddc1 Mon Sep 17 00:00:00 2001 From: Rob Landley Date: Wed, 29 Jan 2020 19:47:31 -0600 Subject: Quick and dirty "echo $ABC" support, done totally the wrong way, but it makes those two remaining tests pass. --- toys/pending/sh.c | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/toys/pending/sh.c b/toys/pending/sh.c index 98f5a17e..bba410aa 100644 --- a/toys/pending/sh.c +++ b/toys/pending/sh.c @@ -217,8 +217,6 @@ static char *getvar(char *s) return getvarlen(s, strlen(s)); } - - // returns pointer to next unquoted (or double quoted if dquot) char. // handle \ '' "" `` $() int skip_quote(char *s, int dquot, int *depth) @@ -304,6 +302,15 @@ static void expand_arg_nobrace(struct sh_arg *arg, char *old, unsigned flags, // ${ $(( $( $[ $' ` " ' +// TODO this is wrong + if (*new == '$') { + char *s = getvar(new+1); + + if (new != old) free(new); + if (!s) return; + new = xstrdup(s); + } + /* while (*s) { if (!quote && !(flags&NO_BRACE) && *s == '{') { @@ -333,8 +340,9 @@ TODO this recurses } */ +// TODO not else? // quote removal - if (!(flags&NO_QUOTE)) { + else if (!(flags&NO_QUOTE)) { int to = 0, from = 0; for (;;) { @@ -915,7 +923,7 @@ if (BUGBUG) { int i; dprintf(255, "envlen=%d arg->c=%d run=", envlen, arg->c); f env[ll] = sss; break; } - if (ll == kk) array_add(&env, kk, sss); + if (ll == kk) array_add(&env, kk++, sss); } environ = env; } -- cgit v1.2.3