From patchwork Sun Dec 18 20:16:06 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mihail Konev X-Patchwork-Id: 9479389 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 2DB9360237 for ; Sun, 18 Dec 2016 20:23:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1B54928456 for ; Sun, 18 Dec 2016 20:23:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0C1B0284C8; Sun, 18 Dec 2016 20:23:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, FREEMAIL_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 00B8628456 for ; Sun, 18 Dec 2016 20:23:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1757606AbcLRUXf (ORCPT ); Sun, 18 Dec 2016 15:23:35 -0500 Received: from forward16p.cmail.yandex.net ([87.250.241.143]:33766 "EHLO forward16p.cmail.yandex.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753709AbcLRUXf (ORCPT ); Sun, 18 Dec 2016 15:23:35 -0500 X-Greylist: delayed 436 seconds by postgrey-1.27 at vger.kernel.org; Sun, 18 Dec 2016 15:23:34 EST Received: from smtp1h.mail.yandex.net (smtp1h.mail.yandex.net [84.201.187.144]) by forward16p.cmail.yandex.net (Yandex) with ESMTP id EFC5921A1F for ; Sun, 18 Dec 2016 23:16:15 +0300 (MSK) Received: from smtp1h.mail.yandex.net (localhost.localdomain [127.0.0.1]) by smtp1h.mail.yandex.net (Yandex) with ESMTP id CC70F8C0D5B for ; Sun, 18 Dec 2016 23:16:15 +0300 (MSK) Received: by smtp1h.mail.yandex.net (nwsmtp/Yandex) with ESMTPSA id Fr4B73nYLx-GEBqXGRl; Sun, 18 Dec 2016 23:16:14 +0300 (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (Client certificate not present) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ya.ru; s=mail; t=1482092174; bh=qq9fNh2Rsda4Ellth9xYOoJbjG/q9jRKfBnnFppGFgU=; h=Date:From:To:Subject:Message-ID; b=g0uy6QGlkspEcvQYyPqDkTO4yljqGZ/lgCEa9+RyQoh//GaAEHjTlK4nd4VjqxX/J WJBlYSYnir4RaEyqaxC/SZHt40sZWLXu9JlbAJEr5FAZsLoyN2yZYWS2rzatQOvuej xS3Kn2XsRq78ZDieBKZLOwnWOYUATq+Lk0z2ImhM= Authentication-Results: smtp1h.mail.yandex.net; dkim=pass header.i=@ya.ru X-Yandex-Suid-Status: 1 0 Date: Mon, 19 Dec 2016 01:16:06 +0500 From: Mihail Konev To: dash@vger.kernel.org Subject: [PATCH] builtin: Fix 'echo --' handling Message-ID: <20161218201606.GA19607@localhost> Mail-Followup-To: Mihail Konev , dash@vger.kernel.org MIME-Version: 1.0 Content-Disposition: inline Sender: dash-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- 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; }