summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorнаб <nabijaczleweli@nabijaczleweli.xyz>2023-02-07 20:33:47 +0100
committerHerbert Xu <herbert@gondor.apana.org.au>2024-04-06 16:53:03 +0800
commit459e51a2ae9d720b12e44fa725a6014a4d784d7c (patch)
treeaeca92d4bf47ebb5f8fb6584364b80b3acbb9e43
parent7884dcced4c04c036b5227207e63a0d06f19e9d7 (diff)
downloaddash-459e51a2ae9d720b12e44fa725a6014a4d784d7c.tar.gz
histedit: Don't include the current fc in out-of-range last
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 <harald@gigawatt.nl> Reported-in: https://marc.info/?l=dash&m=154707728009743&w=2 Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
-rw-r--r--src/histedit.c2
1 files changed, 2 insertions, 0 deletions
diff --git a/src/histedit.c b/src/histedit.c
index fcd8af0..07dd1b4 100644
--- a/src/histedit.c
+++ b/src/histedit.c
@@ -479,6 +479,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)