aboutsummaryrefslogtreecommitdiff
path: root/shell/hush.c
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-04-11 01:15:33 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2018-04-11 01:15:33 +0200
commit89e9d5534d0e8879803ed9dbb25dff3989c31202 (patch)
treeb1f7c630418dd97e4fad62d114381d0297460d52 /shell/hush.c
parent3632cb15f16a7596a68dccfd66a2ad9496bf9fd9 (diff)
downloadbusybox-89e9d5534d0e8879803ed9dbb25dff3989c31202.tar.gz
hush: do not drop backslash from eval 'echo ok\'
newer bash does not drop it, most other shells too function old new delta unbackslash 39 57 +18 parse_stream 2753 2751 -2 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 1/1 up/down: 18/-2) Total: 16 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'shell/hush.c')
-rw-r--r--shell/hush.c22
1 files changed, 17 insertions, 5 deletions
diff --git a/shell/hush.c b/shell/hush.c
index 3afb70cb0..523fc1a31 100644
--- a/shell/hush.c
+++ b/shell/hush.c
@@ -83,7 +83,7 @@
* Status of [[ support:
* [[ args ]] are CMD_SINGLEWORD_NOGLOB:
* v='a b'; [[ $v = 'a b' ]]; echo 0:$?
- * [[ /bin/* ]]; echo 0:$?
+ * [[ /bin/n* ]]; echo 0:$?
* TODO:
* &&/|| are AND/OR ops, -a/-o are not
* quoting needs to be considered (-f is an operator, "-f" and ""-f are not; etc)
@@ -1426,8 +1426,19 @@ static char *unbackslash(char *src)
{
char *dst = src = strchrnul(src, '\\');
while (1) {
- if (*src == '\\')
+ if (*src == '\\') {
src++;
+ if (*src != '\0') {
+ /* \x -> x */
+ *dst++ = *src++;
+ continue;
+ }
+ /* else: "\<nul>". Do not delete this backslash.
+ * Testcase: eval 'echo ok\'
+ */
+ *dst++ = '\\';
+ /* fallthrough */
+ }
if ((*dst++ = *src++) == '\0')
break;
}
@@ -5392,16 +5403,17 @@ static struct pipe *parse_stream(char **pstring,
continue; /* get next char */
case '\\':
/*nommu_addchr(&ctx.as_string, '\\'); - already done */
+ o_addchr(&ctx.word, '\\');
ch = i_getch(input);
if (ch == EOF) {
- /* Ignore this '\'. Testcase: eval 'echo Ok\' */
-#if !BB_MMU
+ /* Testcase: eval 'echo Ok\' */
+
+#if 0 /* bash-4.3.43 was removing backslash, but 4.4.19 retains it, most other shells too */
/* Remove trailing '\' from ctx.as_string */
ctx.as_string.data[--ctx.as_string.length] = '\0';
#endif
continue; /* get next char */
}
- o_addchr(&ctx.word, '\\');
/* Example: echo Hello \2>file
* we need to know that word 2 is quoted
*/