From patchwork Tue Feb 7 19:33:25 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?0L3QsNCx?= X-Patchwork-Id: 13132066 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 C335BC636D3 for ; Tue, 7 Feb 2023 19:33:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232088AbjBGTdz (ORCPT ); Tue, 7 Feb 2023 14:33:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40780 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231772AbjBGTdr (ORCPT ); Tue, 7 Feb 2023 14:33:47 -0500 Received: from tarta.nabijaczleweli.xyz (unknown [139.28.40.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 41DA03CE0C for ; Tue, 7 Feb 2023 11:33:29 -0800 (PST) Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id C232411C4; Tue, 7 Feb 2023 20:33:26 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nabijaczleweli.xyz; s=202211; t=1675798406; bh=+zPNgPih9bH/NvfdpusETLSd0TrgWTt+UCzMQH6RvzA=; h=Date:From:To:Subject:References:In-Reply-To:From; b=QPXoyeHbl3ZT0pyC52AB/BOPXYxgIk3iJmuffQms2HSiN0u3Z6jHkX5ia2eaSil9J b7NmqKL9fopTlek/o7FOyv1aUVhKISaXOKLRf/2HQP177D4wQ7UeHstVWmsE5Z0dMY yI8tvc/B59MkAP/GtIVEBqVEi19aw64NxgvDYC4gpcv+7xNqBbDJJ8QMdOqsd4VRqI s7SAN/8Dn6wwzXt94pDNVVPmxApTdEOcEsokqaNUjHBbEFcMxDe4uq85KrroI8RM4F GsCJxGIr10elRAWGbfbaRuM+OTDzHhlu6ZPJpHjwEANINJExO8Fx7UP+PJCVhcQ6Mj rzUVDw3tZZHJA== Date: Tue, 7 Feb 2023 20:33:25 +0100 From: =?utf-8?b?0L3QsNCx?= To: Harald van Dijk , dash@vger.kernel.org Subject: [PATCH 1/6] fc -s: refuse multiple events instead of ignoring Message-ID: <96c003b30fc95cdf5aed3162901abaa9b89430e2.1675798292.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 The POSIX SYNOPSIS (and our manual which steals it verbatim) says: fc -s [old=new] [first] and, indeed, we only use the first non-= argument instead of enforcing the usage, which is confusing. bash: 2025 ls 2026 id $ fc -s ls=who 2025 2026 who nabijaczleweli pts/2 2023-02-07 17:36 (192.168.1.109) nabijaczleweli pts/3 2023-02-07 17:38 (192.168.1.109) nabijaczleweli pts/4 2023-02-07 16:58 (192.168.1.109) nabijaczleweli pts/5 2023-02-07 17:45 (192.168.1.109) ksh93: 240 id 241 ls $ fc -s ls=who 241 240 ksh: hist: -e - requires single argument yash: 2 ls 3 id $ fc -s ls=who 2 3 fc: too many operands are specified zsh: 2 id 3 ls tarta% fc -s ls=who 3 2 fc: bad option: -s dash (before): 1 ls 2 id $ fc -s ls=who 1 2 who nabijaczleweli pts/2 2023-02-07 17:36 (192.168.1.109) nabijaczleweli pts/3 2023-02-07 17:38 (192.168.1.109) nabijaczleweli pts/4 2023-02-07 16:58 (192.168.1.109) nabijaczleweli pts/5 2023-02-07 17:45 (192.168.1.109) dash (after): 1 ls 2 id $ fc -s ls=who 1 2 src/dash: 3: fc: -s takes one history argument Adapted-from: NetBSD src bin/sh/histedit.c rev 1.38 by aymeric@ --- Here's a quick few that fix my report and a couple of the ones you list at the end of that thread. src/histedit.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/histedit.c b/src/histedit.c index f5c90ab..fc87283 100644 --- a/src/histedit.c +++ b/src/histedit.c @@ -296,6 +296,13 @@ histcmd(int argc, char **argv) *repl++ = '\0'; argc--, argv++; } + + /* + * If -s is specified, accept only one operand + */ + if (sflg && argc >= 2) + sh_error("too many args"); + /* * determine [first] and [last] */ From patchwork Tue Feb 7 19:33:30 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?0L3QsNCx?= X-Patchwork-Id: 13132067 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 07799C636CC for ; Tue, 7 Feb 2023 19:33:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231964AbjBGTdz (ORCPT ); Tue, 7 Feb 2023 14:33:55 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231890AbjBGTdr (ORCPT ); Tue, 7 Feb 2023 14:33:47 -0500 Received: from tarta.nabijaczleweli.xyz (unknown [139.28.40.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 2E5DB3CE2A for ; Tue, 7 Feb 2023 11:33:32 -0800 (PST) Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id 5E7E2168C; Tue, 7 Feb 2023 20:33:31 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nabijaczleweli.xyz; s=202211; t=1675798411; bh=oG85JYBGvLuuf1f9mnO1Hi0KC6QwnxIWND62LdFm5YM=; h=Date:From:To:Subject:References:In-Reply-To:From; b=MTsGBSNvbWymwlR9Ok6vZ9koUNk122Gt6GjTSDh0baTUoAlmuS7hEyGmZqXb6Dmqs OpqEpmWHFNL7lqO1DAclYNnpWgYiuy4uUR46WqE803jfsP+10AQujqd8sop4zH41qN JUb5qDceZbB1rgbAjQ8E5MxO5zcRu/sZKezvrhMvYnS12ipsh/tCkKbq3YXm97Thqj RKjVEnjsJVjEsL4g+FBM2+eBec755xoU4cZyHJJIZg5gsI/MxCfq0S9EWMDQQMEz87 /UYcbt5XUK56bw/QzejfJ0/ZdNnRoGjkNl1jATwWTgicAZtxj4yscC+s0KNEzfcwg1 H3td1uF5yjKaQ== Date: Tue, 7 Feb 2023 20:33:30 +0100 From: =?utf-8?b?0L3QsNCx?= To: Harald van Dijk , dash@vger.kernel.org Subject: [PATCH 2/6] fc -s: don't loop forever when executing the latest entry Message-ID: <7166822efa32d227a28d86bd1fb505f09bb7cf0c.1675798292.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 Quoting CVS comment: Ensure [...] that we break out of the loop after executing it. With the previous code, because the re-executed command was added to the history, it would think that it still had to execute it, leading to an infinite loop. The last thing which differs from ksh is that we get the "fc -s" command into the history, but this is actually rather a feature in my humble opinion. POSIX disagrees: [W]hen the -l option is not specified, the resulting lines shall be entered at the end of the history list and then re-executed by sh. The fc command that caused the editing shall not be entered into the history list. But this is a separate issue, since even without -s dash puts fc into the history (i.e. id; ls; fc 1 2; fc -l; yields 1=id, 2=ls, 3=fc -l). Test cases: $ id uid=1000(nabijaczleweli) gid=100(users) groups=100(users) $ fc -s 1 id uid=1000(nabijaczleweli) gid=100(users) groups=100(users) $ fc -l 1 id 2 fc -s 1 3 id -- >8 -- $ ls autogen.sh ChangeLog ... $ id uid=1000(nabijaczleweli) gid=100(users) groups=100(users) $ fc -s -1 id uid=1000(nabijaczleweli) gid=100(users) groups=100(users) -- >8 -- $ ls autogen.sh ChangeLog ... $ id uid=1000(nabijaczleweli) gid=100(users) groups=100(users) $ fc -s -2 ls autogen.sh ChangeLog ... -- >8 -- $ ls autogen.sh ChangeLog ... $ id uid=1000(nabijaczleweli) gid=100(users) groups=100(users) $ fc -s -2 ls autogen.sh ChangeLog ... $ id 1 uid=1(daemon) gid=1(daemon) groups=1(daemon) $ id 2 uid=2(bin) gid=2(bin) groups=2(bin) $ fc -s 3 fc -s -2 id 1 uid=1(daemon) gid=1(daemon) groups=1(daemon) $ fc -l 1 ls 2 id 3 fc -s -2 4 ls 5 id 1 6 id 2 7 fc -s 3 8 id 1 -- >8 -- $ id 1 uid=1(daemon) gid=1(daemon) groups=1(daemon) $ fc -s 2 fc -s 2 fc -s 2 fc -s 2 fc -s 2 src/dash: 1: fc: called recursively too many times and I'm happy to call this "behaving exactly as I expected when I was typing it in", so removing the XXX. Adapted-from: NetBSD src bin/sh/histedit.c rev 1.38 by aymeric@ --- src/histedit.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/histedit.c b/src/histedit.c index fc87283..28956ec 100644 --- a/src/histedit.c +++ b/src/histedit.c @@ -382,12 +382,10 @@ histcmd(int argc, char **argv) evalstring(s, 0); if (displayhist && hist) { - /* - * XXX what about recursive and - * relative histnums. - */ history(hist, &he, H_ENTER, s); } + + break; } else fputs(s, efp); } From patchwork Tue Feb 7 19:33:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?0L3QsNCx?= X-Patchwork-Id: 13132068 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 51911C636D3 for ; Tue, 7 Feb 2023 19:34:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232169AbjBGTd5 (ORCPT ); Tue, 7 Feb 2023 14:33:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41022 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231965AbjBGTdx (ORCPT ); Tue, 7 Feb 2023 14:33:53 -0500 Received: from tarta.nabijaczleweli.xyz (unknown [139.28.40.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5AF1C3B679 for ; Tue, 7 Feb 2023 11:33:36 -0800 (PST) Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id 8F9C4112A; Tue, 7 Feb 2023 20:33:35 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nabijaczleweli.xyz; s=202211; t=1675798415; bh=s9a5VEdd5M72aC5a/PehrFUxQ+XzrSa5PXh8d8pnvQo=; h=Date:From:To:Subject:References:In-Reply-To:From; b=hLdQT38qw/l/cikbXBgFD8GFswoRBMRJU4Rq1Vysq2qYdNRq2EQjGtO6bkrFG9tbG 6jro/wci1fUnGALCRW36ZznS/uXsaiiwl00p1MNDWXCm7o3Z9PGHAtly/Y1sFPSPFg DQFCN+iTsSKjuDLnwVIuNXK+Td7ZUf9/ZSqf4Vq87wPKYq3L/6zwf7MTZCB1QtMkjF 6bkMkWhia0v38zL49YgA8Db+h7Fe24DVYF4RtR8j79cQwZ1suiDD0Cz4UVq5TlD5dn 4eNE0uMCyQQ0mxtsn/g8g8+TG0K6yuNpX2SaUaJuDvERRTerSdlgsRKSgWQlfFgK0n 6SNrXsdrX8ckA== Date: Tue, 7 Feb 2023 20:33:34 +0100 From: =?utf-8?b?0L3QsNCx?= To: Harald van Dijk , dash@vger.kernel.org Subject: [PATCH 3/6] fc: only parse old=new if -s, per POSIX Message-ID: <717f18e61d425cc96d2af5ac3f2c5f1de230f5d3.1675798292.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 Before (erroneously replaced): $ a=b set ... $ fc a=b 8 , b=b set After (used as search string): $ fc a=b 8 , a=b set Reported-by: Harald van Dijk Reported-in: https://marc.info/?l=dash&m=154707728009743&w=2 --- src/histedit.c | 21 +++++++++------------ 1 file changed, 9 insertions(+), 12 deletions(-) diff --git a/src/histedit.c b/src/histedit.c index 28956ec..24631ca 100644 --- a/src/histedit.c +++ b/src/histedit.c @@ -288,21 +288,18 @@ histcmd(int argc, char **argv) } /* - * If executing, parse [old=new] now + * If -s is specified, accept [old=new] first only */ - if (lflg == 0 && argc > 0 && - ((repl = strchr(argv[0], '=')) != NULL)) { - pat = argv[0]; - *repl++ = '\0'; - argc--, argv++; + if (sflg) { + if (argc > 0 && ((repl = strchr(argv[0], '=')) != NULL)) { + pat = argv[0]; + *repl++ = '\0'; + argc--, argv++; + } + if (argc >= 2) + sh_error("too many args"); } - /* - * If -s is specified, accept only one operand - */ - if (sflg && argc >= 2) - sh_error("too many args"); - /* * determine [first] and [last] */ From patchwork Tue Feb 7 19:33:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?0L3QsNCx?= X-Patchwork-Id: 13132071 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 137D3C636D4 for ; Tue, 7 Feb 2023 19:34:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231772AbjBGTeD (ORCPT ); Tue, 7 Feb 2023 14:34:03 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41026 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232047AbjBGTdy (ORCPT ); Tue, 7 Feb 2023 14:33:54 -0500 Received: from tarta.nabijaczleweli.xyz (unknown [139.28.40.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 7E00E3B670 for ; Tue, 7 Feb 2023 11:33:40 -0800 (PST) Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id B426A942; Tue, 7 Feb 2023 20:33:39 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nabijaczleweli.xyz; s=202211; t=1675798419; bh=LFLA99HyYUBNUwoTrehEu2zy8RwDT7JJG6bmJkWYQmk=; h=Date:From:To:Subject:References:In-Reply-To:From; b=Vdq6uwNpj095FXg/1ZQNyvbD9fwBRapdeX5/MVfR+QSHO0V/M6XMuwZkgIRnXYdtf 17P1iUl7GG08tNdq8IicgYNdX94eojI3lgMH3+sx97B0zoeFbpmPf8K85lmeEerW0W KgIiPICPtiXjpskAbQUuABumcmWecJqXFKzwlyWWjBpUIG/00Jpm17cL+wnjxFw05G CtdgEy6m++lV/PECgi1r6h+Pr3DBa8g/Iu889w58saC4Z0K0JyD4AvnYRi4Bzdo3m6 aJ6R7Cd6mHcyiAPzbyKbm+LPV2N6wD6KSMD1ELEepn6LXqsJZmmSBu2x4bv2aHlt8b zCAHSjFxEInsQ== Date: Tue, 7 Feb 2023 20:33:38 +0100 From: =?utf-8?b?0L3QsNCx?= To: Harald van Dijk , dash@vger.kernel.org Subject: [PATCH 4/6] fc: don't require an argument 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 is already handled correctly (per POSIX) below: When the synopsis form with -s is used: If first is omitted, the previous command shall be used. For the synopsis forms without -s: If first and last are both omitted, the previous 16 commands shall be listed or the previous single command shall be edited (based on the -l option). Test log: $ ls autogen.sh ChangeLog ... $ id uid=1000(nabijaczleweli) gid=100(users) groups=100(users) $ who nabijaczleweli pts/2 2023-02-07 18:36 (192.168.1.109) $ fc 4 , who q nabijaczleweli pts/2 2023-02-07 18:36 (192.168.1.109) $ fc -l 1 ls 2 id 3 who 4 fc $ fc -s fc -l 1 ls 2 id 3 who 4 fc 5 fc -l Reported-by: Harald van Dijk Reported-in: https://marc.info/?l=dash&m=154707728009743&w=2 --- src/histedit.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/histedit.c b/src/histedit.c index 24631ca..f10e5ab 100644 --- a/src/histedit.c +++ b/src/histedit.c @@ -212,9 +212,6 @@ histcmd(int argc, char **argv) if (hist == NULL) sh_error("history not active"); - if (argc == 1) - sh_error("missing history argument"); - #ifdef __GLIBC__ optind = 0; #else From patchwork Tue Feb 7 19:33:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?0L3QsNCx?= X-Patchwork-Id: 13132069 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 DD9AFC636CC for ; Tue, 7 Feb 2023 19:34:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232035AbjBGTd7 (ORCPT ); Tue, 7 Feb 2023 14:33:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:41032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232039AbjBGTdy (ORCPT ); Tue, 7 Feb 2023 14:33:54 -0500 Received: from tarta.nabijaczleweli.xyz (unknown [139.28.40.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id B2CA43EFE4 for ; Tue, 7 Feb 2023 11:33:44 -0800 (PST) Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id EE40710CA; Tue, 7 Feb 2023 20:33:43 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nabijaczleweli.xyz; s=202211; t=1675798424; bh=B6q9ZevxjZFqj+JgoXImeHSf4CBX9uAxhRtszJMSlJw=; h=Date:From:To:Subject:References:In-Reply-To:From; b=O5llsGvhg+GupuxjuvGGhjFwjHaanF16l2WBG9ksfXzUbgAU8bY9XeUHCrt69SVtn zYu14Gik6Tg4CJ2qX+JqRUDjgSGzu2wzYj5TazYq+JOY9jJu7HxE+JHpa/dLXA3W0X FWmDSK+fXevLiVagcmi++W6w4KMnXzW9pmmxyirNqVI/jmEEO63O6EEkBeLnR/speI dEOFurJPZu9uGDW1g6vacgb5DHQqxIqMkaAZkdlmTffsXp5gknPLYp7OOtRDBe56M5 gyhypFH10NlXHzBgMjYQD1g5iQn+Blt6xtE/AjW2B8NwmO5j8TlQZkrmTRpw2lxAko zDFuo6/eYxcqg== Date: Tue, 7 Feb 2023 20:33:42 +0100 From: =?utf-8?b?0L3QsNCx?= To: Harald van Dijk , dash@vger.kernel.org Subject: [PATCH 5/6] fc: fix "fc -3" extension on glibc Message-ID: <0ea78f2dddbb59ce2c984c83ab45cd811191b499.1675798292.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 Before: $ echo a a $ echo b b $ fc -2 -1 src/dash: 3: fc: unknown option: -2 $ fc -- -2 -1 16 ,p echo b fc -2 -1 After: $ echo a a $ echo b b $ fc -2 -1 6 ,p echo a echo b Reported-by: Harald van Dijk Reported-in: https://marc.info/?l=dash&m=154707728009743&w=2 --- src/histedit.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/histedit.c b/src/histedit.c index f10e5ab..502ad40 100644 --- a/src/histedit.c +++ b/src/histedit.c @@ -217,7 +217,7 @@ histcmd(int argc, char **argv) #else optreset = 1; optind = 1; /* initialize getopt */ #endif - while (not_fcnumber(argv[optind]) && + while (not_fcnumber(argv[optind ?: 1]) && (ch = getopt(argc, argv, ":e:lnrs")) != -1) switch ((char)ch) { case 'e': @@ -243,6 +243,7 @@ histcmd(int argc, char **argv) sh_error("unknown option: -%c", optopt); /* NOTREACHED */ } + optind = optind ?: 1; argc -= optind, argv += optind; /* From patchwork Tue Feb 7 19:33:47 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?0L3QsNCx?= X-Patchwork-Id: 13132070 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 B1513C636D3 for ; Tue, 7 Feb 2023 19:34:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231866AbjBGTeC (ORCPT ); Tue, 7 Feb 2023 14:34:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231772AbjBGTdz (ORCPT ); Tue, 7 Feb 2023 14:33:55 -0500 Received: from tarta.nabijaczleweli.xyz (unknown [139.28.40.42]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 5BDBF3EFF7 for ; Tue, 7 Feb 2023 11:33:49 -0800 (PST) Received: from tarta.nabijaczleweli.xyz (unknown [192.168.1.250]) by tarta.nabijaczleweli.xyz (Postfix) with ESMTPSA id 3882F1700; Tue, 7 Feb 2023 20:33:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=nabijaczleweli.xyz; s=202211; t=1675798428; bh=XSavRGu0cDLQdSb1Y1rEcZmnlDRJe1qhHq/2iQgR5ZY=; h=Date:From:To:Subject:References:In-Reply-To:From; b=SCzLVzd/ZsLZE6IZx68gnCZQBnhslJHOZ8CokRd/2c01IupnnFGQLKz1qNJJToopP d9pql9dzYVxk11xbk6Q8PQhrnd/swQFBW4NVej4CB9wbMfzD0kBMm5lMawSrWUJmxl /97qGPlgdxzLDSjOZ0OHKBFozVlz9qeZJrrrzDpwCAzb+B4y+EPc0y7JP1Yf+7TDlU PnOVw3L7zEGTMkMkiI8/mKChQv+7dbdbGTezy2DE9DNVKNrRBr7M6p1P/GN5UWpIDq 9hVGyWTD4Q44WZyac1g5NqC1NFiePx4iKEGEHhPMGRO50yOYWjpOTBwffBK/YK7RWX v2VqYN5mT8k+A== Date: Tue, 7 Feb 2023 20:33:47 +0100 From: =?utf-8?b?0L3QsNCx?= To: Harald van Dijk , dash@vger.kernel.org Subject: [PATCH 6/6] fc: don't include the current fc in out-of-range last 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 POSIX states: When a range of commands is used, it shall not be an error to specify first or last values that are not in the history list; fc shall substitute the value representing the oldest or newest command in the list, as appropriate. For example, if there are only ten commands in the history list, numbered 1 to 10: fc -l fc 1 99 shall list and edit, respectively, all ten commands. Which would seem to imply that the current fc shouldn't be included (well, in the POSIX model, no non--l fc enters the history, so that reinforces that). zsh, bash, mksh, yash all agree with this; oddly, ksh includes it. Before: $ 1 src/dash: 1: 1: not found $ 2 src/dash: 2: 2: not found $ 3 src/dash: 3: 3: not found $ 4 src/dash: 4: 4: not found $ 5 src/dash: 5: 5: not found $ 6 src/dash: 6: 6: not found $ fc 1 999 21 ,p 1 2 3 4 5 6 fc 1 999 After: $ fc 1 9999 12 ,p 1 2 3 4 5 6 Reported-by: Harald van Dijk Reported-in: https://marc.info/?l=dash&m=154707728009743&w=2 --- src/histedit.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/histedit.c b/src/histedit.c index 502ad40..7692776 100644 --- a/src/histedit.c +++ b/src/histedit.c @@ -476,6 +476,8 @@ str_to_event(const char *str, int last) */ retval = history(hist, &he, last ? H_FIRST : H_LAST); + if (retval != -1 && last) + retval = history(hist, &he, H_NEXT); } } if (retval == -1)