ash: fix bug 571 (jobs %string misbehaving)
[oweals/busybox.git] / shell / hush.c
index d7b479d645956e8c718fa4a1084c593f6c029711..08e7f505257989eabb9c114ebbbb5f63334296e5 100644 (file)
@@ -58,6 +58,7 @@
  * TODOs:
  *      grep for "TODO" and fix (some of them are easy)
  *      builtins: ulimit
+ *      special variables (PWD etc)
  *      follow IFS rules more precisely, including update semantics
  *      export builtin should be special, its arguments are assignments
  *          and therefore expansion of them should be "one-word" expansion:
@@ -6037,6 +6038,8 @@ static struct pipe *parse_stream(char **pstring,
                        dest.o_assignment = NOT_ASSIGNMENT;
                }
 
+               /* Note: nommu_addchr(&ctx.as_string, ch) is already done */
+
                switch (ch) {
                case '#':
                        if (dest.length == 0) {
@@ -6060,12 +6063,17 @@ static struct pipe *parse_stream(char **pstring,
                        ch = i_getch(input);
                        if (ch != '\n') {
                                o_addchr(&dest, '\\');
-                               nommu_addchr(&ctx.as_string, '\\');
+                               /*nommu_addchr(&ctx.as_string, '\\'); - already done */
                                o_addchr(&dest, ch);
                                nommu_addchr(&ctx.as_string, ch);
                                /* Example: echo Hello \2>file
                                 * we need to know that word 2 is quoted */
                                dest.o_quoted = 1;
+                       } else {
+#if !BB_MMU
+                               /* It's "\<newline>". Remove trailing '\' from ctx.as_string */
+                               ctx.as_string.data[--ctx.as_string.length] = '\0';
+#endif
                        }
                        break;
                case '$':