From patchwork Wed Jan 4 11:33:45 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?0L3QsNCx?= X-Patchwork-Id: 13088500 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3825C4332F for ; Wed, 4 Jan 2023 11:33:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234001AbjADLdv (ORCPT ); Wed, 4 Jan 2023 06:33:51 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51366 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234268AbjADLdu (ORCPT ); Wed, 4 Jan 2023 06:33:50 -0500 Received: from tarta.nabijaczleweli.xyz (unknown [139.28.40.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 720CFF0D for ; Wed, 4 Jan 2023 03:33:49 -0800 (PST) Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id 7790C650; Wed, 4 Jan 2023 12:33:46 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nabijaczleweli.xyz; s=202211; t=1672832026; bh=+9ZYAQnw0dnvfNmHkoJ6pachmekwMilPvZFeSybxkLQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=M1o26AOW1V48+i8/jgVvwJ1Y8Nxy1DVjyDbRZxiayh5gNh1u5Z8JLJ9N+ILJRLrY2 BhdQLNhJRsdclpKeqtmmZjZmB1AnnBZS6hVMK7Ian/9sYGOhz5vOqRFSmNg2MXRCRN n54wzQrQAMJSuBM9hUQK0jP1/TtHpJfhekoQIK0hYLsbuox8lsHw5zjLiyA8wy5JiE 5DZq8uAKZyhRrZtpmDezy0h8Xk8QkCD4tmiFZ2zFjkAjv++CBx2WtpEbCDPwkVzIrQ Ow2lTnHlcaLjqadAEPk0ZHfpjkIgeQa6yVBlxgEC/wN5rkJB90w3V/Wih7lPV0C2qb M9XcG4li1Gvnw== Date: Wed, 4 Jan 2023 12:33:45 +0100 From: =?utf-8?b?0L3QsNCx?= To: Herbert Xu Cc: dash@vger.kernel.org Subject: [PATCH v2 1/2] options: getopts: ignore first --, per POSIX Message-ID: <728796762ed62a1e9a38cf62762e57509e5027a2.1672831998.git.nabijaczleweli@nabijaczleweli.xyz> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20220429 Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org Issue 7, XCU, getopts, OPTIONS reads "None.", and getopts isn't a special built-in listed in sexion 2.14 ‒ this means that XCU, 1. Introduction, 1.4 Utility Description Defaults, OPTIONS, Default Behavior applies: Default Behavior: When this section is listed as "None.", it means that the implementation need not support any options. Standard utilities that do not accept options, but that do accept operands, shall recognize "--" as a first argument to be discarded. Test with: getopts -- d: a Correct output is no output, exit 1 Wrong output errors out with d: being an invalid argument name --- src/options.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/options.c b/src/options.c index a46c23b..337a8ee 100644 --- a/src/options.c +++ b/src/options.c @@ -409,6 +409,9 @@ getoptscmd(int argc, char **argv) { char **optbase; + nextopt(nullstr); + argc -= argptr - argv - 1; + argv = argptr - 1; if (argc < 3) sh_error("Usage: getopts optstring var [arg]"); else if (argc == 3) { From patchwork Wed Jan 4 11:35:13 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?0L3QsNCx?= X-Patchwork-Id: 13088501 X-Patchwork-Delegate: herbert@gondor.apana.org.au Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 889ADC4332F for ; Wed, 4 Jan 2023 11:35:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234871AbjADLfQ (ORCPT ); Wed, 4 Jan 2023 06:35:16 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52236 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234645AbjADLfP (ORCPT ); Wed, 4 Jan 2023 06:35:15 -0500 Received: from tarta.nabijaczleweli.xyz (unknown [139.28.40.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 1D7D2EAF for ; Wed, 4 Jan 2023 03:35:15 -0800 (PST) Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id 6B299652; Wed, 4 Jan 2023 12:35:14 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nabijaczleweli.xyz; s=202211; t=1672832114; bh=JIvJ+jmIdHcZ41bhPHwL9sdN33SD7wo41BhW/RjdjHQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=eKN7PFTBhP59dOgbTxNzXlhzmmg8yJD2otl85/uicy8xF4WOczkiUHuNn+30FV/in D5Und+P2iItzWiOrIAIfR5CpdXxNVf+imhYT3xPiLW38/FgOkHDyOSDNv6lsucmn+x sGu0TjVwkp26ZvW5vVWpZTfpnsrs02nWxNGmNQpa67UhqB2wMGh7ZNt7wOLeFs8qD6 hOCPC7VsHJrjMVLEB0ZoUduD7hmmWEbi3xRL4iTYhOlYT4/6S/6Qwsz3UHuYKGDK0x 1xZ7EJfz+fZkv3MzZC/hfDKrrM6NVm37fSfMRCa6LvPxmZA358XYXDH0scjb51qVBQ 2cwVf+FVr0JvA== Date: Wed, 4 Jan 2023 12:35:13 +0100 From: =?utf-8?b?0L3QsNCx?= To: Herbert Xu Cc: dash@vger.kernel.org Subject: [PATCH v2 2/2] exec: type: ignore first -- for consistency Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20220429 Precedence: bulk List-ID: X-Mailing-List: dash@vger.kernel.org This appears to be the only remaining built-in that doesn't use nextopt() to parse its arguments (and isn't forbidden from doing so) ‒ users expect to be able to do this, and it's nice to be consistent here. Test with: type -- ls -- Correct output lists ls=/bin/ls, then --=ENOENT Wrong output lists --=ENOENT, ls=/bin/ls, --=ENOENT Fixes: https://bugs.debian.org/870317 --- src/exec.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/exec.c b/src/exec.c index 87354d4..d61881d 100644 --- a/src/exec.c +++ b/src/exec.c @@ -760,11 +760,11 @@ unsetfunc(const char *name) int typecmd(int argc, char **argv) { - int i; int err = 0; - for (i = 1; i < argc; i++) { - err |= describe_command(out1, argv[i], NULL, 1); + nextopt(nullstr); + while (*argptr) { + err |= describe_command(out1, *argptr++, NULL, 1); } return err; }