Ignore first "--", as the end of options.

Breaks uses that expect 'echo' to output arguments verbatim, but
fixes those that expect 'echo --' to do so (such as 'echo -- -n').

Signed-off-by: Mihail Konev <[email protected]>
---
 src/bltin/printf.c | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/src/bltin/printf.c b/src/bltin/printf.c
index a626cee2c60e..1b3df313f02d 100644
--- a/src/bltin/printf.c
+++ b/src/bltin/printf.c
@@ -450,20 +450,29 @@ int
 echocmd(int argc, char **argv)
 {
        int nonl;
+       int dashdash_met = 0;
 
-       nonl = *++argv ? equal(*argv, "-n") : 0;
+       nonl = (*++argv && !dashdash_met) ? equal(*argv, "-n") : 0;
        argv += nonl;
 
        do {
-               int c;
-
-               if (likely(*argv))
-                       nonl += print_escape_str("%s", NULL, NULL, *argv++);
+               int c = 1;
+
+               if (likely(*argv)) {
+                       if (unlikely(equal(*argv, "--") && !dashdash_met)) {
+                               dashdash_met = 1;
+                               c = 0;
+                       } else
+                               nonl += print_escape_str("%s", NULL, NULL, 
*argv);
+                       argv++;
+               }
                if (likely((nonl + !*argv) > 1))
                        break;
 
-               c = *argv ? ' ' : '\n';
-               out1c(c);
+               if (c) {
+                       c = *argv ? ' ' : '\n';
+                       out1c(c);
+               }
        } while (*argv);
        return 0;
 }
-- 
2.9.2

--
To unsubscribe from this list: send the line "unsubscribe dash" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html

Reply via email to