From: наб <nabijaczleweli@nabijaczleweli.xyz>
To: Harald van Dijk <harald@gigawatt.nl>, dash@vger.kernel.org
Subject: [PATCH 2/6] fc -s: don't loop forever when executing the latest entry
Date: Tue, 7 Feb 2023 20:33:30 +0100 [thread overview]
Message-ID: <7166822efa32d227a28d86bd1fb505f09bb7cf0c.1675798292.git.nabijaczleweli@nabijaczleweli.xyz> (raw)
In-Reply-To: <ab3fbcc2-1a9a-136b-0b02-a5ea31fe02c5@gigawatt.nl>
[-- Attachment #1: Type: text/plain, Size: 2754 bytes --]
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);
}
--
2.30.2
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
next prev parent reply other threads:[~2023-02-07 19:33 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-08 16:10 dash repeats first line in history entry forever with fc -s наб
2023-01-08 16:31 ` Harald van Dijk
2023-01-08 17:01 ` Christoph Anton Mitterer
2023-02-07 19:33 ` [PATCH 1/6] fc -s: refuse multiple events instead of ignoring наб
2024-04-06 8:55 ` Herbert Xu
2023-02-07 19:33 ` наб [this message]
2023-02-07 19:33 ` [PATCH 3/6] fc: only parse old=new if -s, per POSIX наб
2023-02-07 19:33 ` [PATCH 4/6] fc: don't require an argument наб
2023-02-07 19:33 ` [PATCH 5/6] fc: fix "fc -3" extension on glibc наб
2023-02-07 19:33 ` [PATCH 6/6] fc: don't include the current fc in out-of-range last наб
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=7166822efa32d227a28d86bd1fb505f09bb7cf0c.1675798292.git.nabijaczleweli@nabijaczleweli.xyz \
--to=nabijaczleweli@nabijaczleweli.xyz \
--cc=dash@vger.kernel.org \
--cc=harald@gigawatt.nl \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.