From: Mihail Konev <k.mvc@ya.ru>
To: dash@vger.kernel.org
Subject: [PATCH] builtin: Fix 'echo --' handling
Date: Mon, 19 Dec 2016 01:16:06 +0500 [thread overview]
Message-ID: <20161218201606.GA19607@localhost> (raw)
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 <k.mvc@ya.ru>
---
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
next reply other threads:[~2016-12-18 20:23 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-12-18 20:16 Mihail Konev [this message]
2016-12-18 20:28 ` [PATCH] builtin: Fix 'echo --' handling Harald van Dijk
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20161218201606.GA19607@localhost \
--to=k.mvc@ya.ru \
--cc=dash@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).