As I use/try/test many shells, I'm in the habit of using POSIX commands
such as 'fc -l 1' to list the complete history.
If there have been more than $HISTSIZE command, the list is trimmed at
the beginning without renumbering, and bash errors out:
$ fc -l 1
bash-5.0: fc: history specification out of range
This is different from every other shell, and also looks like it's
contrary to the POSIX spec:
https://pubs.opengroup.org/onlinepubs/9699919799/utilities/fc.html#tag_20_44_05
| 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.
The attached patch removes the error and limits the range to available
commands as specified.
- Martijn
--
|| modernish -- harness the shell
|| https://github.com/modernish/modernish
||
|| KornShell lives!
|| https://github.com/ksh93/ksh
diff --git a/builtins/fc.def b/builtins/fc.def
index c266ac2c..7f606c52 100644
--- a/builtins/fc.def
+++ b/builtins/fc.def
@@ -321,10 +321,7 @@ fc_builtin (list)
while (last_hist >= 0 && hlist[last_hist] == 0)
last_hist--;
if (last_hist < 0)
- {
- sh_erange ((char *)NULL, _("history specification"));
- return (EXECUTION_FAILURE);
- }
+ last_hist = 0;
if (list)
{
@@ -353,12 +350,10 @@ fc_builtin (list)
histbeg = histend = last_hist;
}
- /* We print error messages for line specifications out of range. */
- if ((histbeg < 0) || (histend < 0))
- {
- sh_erange ((char *)NULL, _("history specification"));
- return (EXECUTION_FAILURE);
- }
+ if (histbeg < 0)
+ histbeg = 0;
+ if (histend < 0)
+ histend = 0;
/* "When not listing, the fc command that caused the editing shall not be
entered into the history list." */
@@ -382,12 +377,10 @@ fc_builtin (list)
histbeg = last_hist;
}
- /* We print error messages for line specifications out of range. */
- if ((histbeg < 0) || (histend < 0))
- {
- sh_erange ((char *)NULL, _("history specification"));
- return (EXECUTION_FAILURE);
- }
+ if (histbeg < 0)
+ histbeg = 0;
+ if (histend < 0)
+ histend = 0;
if (histend < histbeg)
{