diff options
author | Eric Andersen <andersen@codepoet.org> | 2001-03-09 20:34:46 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2001-03-09 20:34:46 +0000 |
commit | 74e056bfc8e2d6f006548c0134502697c056f97a (patch) | |
tree | 676e4afbfb2edbbbe734d80b05c19706c4fdb37b | |
parent | 3c7361f53aab0d4c6cb3c46218810bda52693fab (diff) | |
download | busybox-74e056bfc8e2d6f006548c0134502697c056f97a.tar.gz |
Fixed a couple more cases. $FOO/bar ${FOO} and such now work
without wordexp. Of course for stuff like ${1:-foo} you still
need wordexp for them to work.
-Erik
-rw-r--r-- | lash.c | 18 | ||||
-rw-r--r-- | sh.c | 18 | ||||
-rw-r--r-- | shell/lash.c | 18 |
3 files changed, 42 insertions, 12 deletions
@@ -1014,7 +1014,6 @@ static int expand_arguments(char *command) * wordexp can't do for us, namely $? and $! */ src = command; while((dst = strchr(src,'$')) != NULL){ - printf("dollar '%s'\n", dst); var = NULL; switch(*(dst+1)) { case '?': @@ -1057,14 +1056,25 @@ static int expand_arguments(char *command) } else { /* Looks like an environment variable */ char delim_hold; - src=strpbrk(dst+1, " \t~`!$^&*()=|\\{}[];\"'<>?."); + int num_skip_chars=1; + int dstlen = strlen(dst); + /* Is this a ${foo} type variable? */ + if (dstlen >=2 && *(dst+1) == '{') { + src=strchr(dst+1, '}'); + num_skip_chars=2; + } else { + src=strpbrk(dst+1, " \t~`!$^&*()=|\\[];\"'<>?./"); + } if (src == NULL) { - src = dst+strlen(dst); + src = dst+dstlen; } delim_hold=*src; *src='\0'; /* temporary */ - var = getenv(dst + 1); + var = getenv(dst + num_skip_chars); *src=delim_hold; + if (num_skip_chars==2) { + src++; + } } if (var == NULL) { /* Seems we got an un-expandable variable. So delete it. */ @@ -1014,7 +1014,6 @@ static int expand_arguments(char *command) * wordexp can't do for us, namely $? and $! */ src = command; while((dst = strchr(src,'$')) != NULL){ - printf("dollar '%s'\n", dst); var = NULL; switch(*(dst+1)) { case '?': @@ -1057,14 +1056,25 @@ static int expand_arguments(char *command) } else { /* Looks like an environment variable */ char delim_hold; - src=strpbrk(dst+1, " \t~`!$^&*()=|\\{}[];\"'<>?."); + int num_skip_chars=1; + int dstlen = strlen(dst); + /* Is this a ${foo} type variable? */ + if (dstlen >=2 && *(dst+1) == '{') { + src=strchr(dst+1, '}'); + num_skip_chars=2; + } else { + src=strpbrk(dst+1, " \t~`!$^&*()=|\\[];\"'<>?./"); + } if (src == NULL) { - src = dst+strlen(dst); + src = dst+dstlen; } delim_hold=*src; *src='\0'; /* temporary */ - var = getenv(dst + 1); + var = getenv(dst + num_skip_chars); *src=delim_hold; + if (num_skip_chars==2) { + src++; + } } if (var == NULL) { /* Seems we got an un-expandable variable. So delete it. */ diff --git a/shell/lash.c b/shell/lash.c index 34dca0449..8f19e526a 100644 --- a/shell/lash.c +++ b/shell/lash.c @@ -1014,7 +1014,6 @@ static int expand_arguments(char *command) * wordexp can't do for us, namely $? and $! */ src = command; while((dst = strchr(src,'$')) != NULL){ - printf("dollar '%s'\n", dst); var = NULL; switch(*(dst+1)) { case '?': @@ -1057,14 +1056,25 @@ static int expand_arguments(char *command) } else { /* Looks like an environment variable */ char delim_hold; - src=strpbrk(dst+1, " \t~`!$^&*()=|\\{}[];\"'<>?."); + int num_skip_chars=1; + int dstlen = strlen(dst); + /* Is this a ${foo} type variable? */ + if (dstlen >=2 && *(dst+1) == '{') { + src=strchr(dst+1, '}'); + num_skip_chars=2; + } else { + src=strpbrk(dst+1, " \t~`!$^&*()=|\\[];\"'<>?./"); + } if (src == NULL) { - src = dst+strlen(dst); + src = dst+dstlen; } delim_hold=*src; *src='\0'; /* temporary */ - var = getenv(dst + 1); + var = getenv(dst + num_skip_chars); *src=delim_hold; + if (num_skip_chars==2) { + src++; + } } if (var == NULL) { /* Seems we got an un-expandable variable. So delete it. */ |