ash: fix bug 571 (jobs %string misbehaving)
[oweals/busybox.git] / shell / hush.c
index 245fb586ddc53707a7eca9e685bcb442dbe8e562..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:
@@ -311,22 +312,9 @@ struct command {
 #if ENABLE_HUSH_BASH_COMPAT
 # define CMD_SINGLEWORD_NOGLOB 2
 #endif
-// Basically, word splitting and pathname expansion should NOT be performed
-// Examples:
-// no word splitting:     a="a b"; [[ $a = "a b" ]]; echo $? should print "0"
-// no pathname expansion: [[ /bin/m* = "/bin/m*" ]]; echo $? should print "0"
-// Additional operators:
-// || and && should work as -o and -a
-// =~ regexp match
-// == should do _pattern match_ against right side. bash does this:
-//      # [[ *a* == bab ]] && echo YES
-//      # [[ bab == *a* ]] && echo YES
-//      YES
-// != does the negated == (i.e., also with pattern matching)
-// Apart from the above, [[ expr ]] should work as [ expr ]
 
 /* used for "export noglob=* glob* a=`echo a b`" */
-/*#define CMD_SINGLEWORD_NOGLOB_COND 3 */
+//#define CMD_SINGLEWORD_NOGLOB_COND 3
 // It is hard to implement correctly, it adds significant amounts of tricky code,
 // and all this is only useful for really obscure export statements
 // almost nobody would use anyway. #ifdef CMD_SINGLEWORD_NOGLOB_COND
@@ -6050,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) {
@@ -6073,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 '$':
@@ -7220,7 +7215,7 @@ static int FAST_FUNC builtin_memleak(char **argv UNUSED_PARAM)
 
        if (!G.memleak_value)
                G.memleak_value = l;
-       
+
        l -= G.memleak_value;
        if ((long)l < 0)
                l = 0;