New -D option for fc to force it to delete history entries selected for editing and re-execution; change readline edit-and-execute-command bindable command so it acts more like an accept-line followed by a command execution than an editing command that returns to readline()

This commit is contained in:
Chet Ramey
2025-12-30 15:55:55 -05:00
parent 2cdb2f9b31
commit 722a855459
15 changed files with 1200 additions and 1087 deletions
+33
View File
@@ -12373,3 +12373,36 @@ lib/readline/bind.c
- show-mode-in-prompt: add V_SPECIAL flag so hack_special_boolean_var()
gets called and _rl_reset_prompt will be called when it's changed
Report and fix from Martin D Kealey <martin@kurahaupo.gen.nz>
12/18
-----
bashjmp.h
- REINIT: new value for jump_to_top_level()
eval.c,shell.c,builtins/evalstring.c
- handle REINIT as a longjmp to top_level value, same as DISCARD
except it doesn't reset last_command_exit_value
builtins/fc.def
- fc_builtin: new option -D. This removes the selected commands
from the history list before calling fc_execute_file to execute
the edited lines.
Currently used by edit_and_execute_command to remove the partial
history entry so it doesn't trip a HISTCONTROL entry of `ignoredups'
if the partial history entry and the first line of the edited file
happen to be the same. It could be used if you made a typo in a
command and wanted to fix it in an editor without the old line
cluttering up the history
bashline.c
- edit_and_execute_command: change implementation so it acts more
like an accept-line followed by command execution instead of a
readline command that returns to editing the same line. The old
behavior is present if the shell isn't running interactively or
readline is getting input from a macro. The new behavior is to
not save or restore any parser state, but reset the parser after
parse_and_execute returns and jump_to_top_level (REINIT)
Inspired by a report from William Pursell <william.r.pursell@gmail.com>
doc/bash.1,doc/bashref.texi
- fc: documented new -D option
+1
View File
@@ -43,5 +43,6 @@ extern int no_longjmp_on_fatal_error;
#define ERREXIT 4 /* Exit due to error condition */
#define SIGEXIT 5 /* Exit due to fatal terminating signal */
#define EXITBLTIN 6 /* Exit due to the exit builtin. */
#define REINIT 7 /* Abandon current command and reinitialize */
#endif /* _BASHJMP_H_ */
+59 -30
View File
@@ -943,17 +943,20 @@ edit_and_execute_command (int count, int c, int editing_mode, const char *edit_c
{
char *command, *metaval;
int r, rrs, metaflag;
int reading_from_tty;
size_t clen;
sh_parser_state_t ps;
rrs = rl_readline_state;
saved_command_line_count = current_command_line_count;
reading_from_tty = interactive && (bash_input.type != st_string) && (RL_ISSTATE (RL_STATE_MACROINPUT) == 0);
/* Accept the current line. */
rl_newline (1, c);
if (rl_explicit_arg)
{
size_t clen;
/* 32 exceeds strlen (itos (INTMAX_MAX)) (19) */
clen = strlen (edit_command) + 32;
command = (char *)xmalloc (clen);
@@ -965,8 +968,6 @@ edit_and_execute_command (int count, int c, int editing_mode, const char *edit_c
then call fc to operate on it. We have to add a dummy command to
the end of the history because fc ignores the last command (assumes
it's supposed to deal with the command before the `fc'). */
/* This breaks down when using command-oriented history and are not
finished with the command, so we should not ignore the last command */
using_history ();
current_command_line_count++; /* for rl_newline above */
bash_add_history (rl_line_buffer);
@@ -974,45 +975,73 @@ edit_and_execute_command (int count, int c, int editing_mode, const char *edit_c
bash_add_history ("");
history_lines_this_session++;
using_history ();
command = savestring (edit_command);
/* XXX - hist_last_line_added = 1; ? */
/* +4 for -D */
clen = strlen (edit_command) + 4;
command = (char *)xmalloc (clen);
snprintf (command, clen, "%s -D", edit_command);
}
/* save needed readline state */
if (reading_from_tty == 0)
{
metaval = rl_variable_value ("input-meta");
metaflag = RL_BOOLEAN_VARIABLE_VALUE (metaval);
}
rl_cleanup_after_signal ();
/* save needed bash state */
if (reading_from_tty == 0)
{
save_parser_state (&ps);
parser_unset_string_list (); /* XXX */
}
metaval = rl_variable_value ("input-meta");
metaflag = RL_BOOLEAN_VARIABLE_VALUE (metaval);
if (rl_deprep_term_function)
(*rl_deprep_term_function) ();
rl_clear_signals ();
save_parser_state (&ps);
parser_unset_string_list ();
r = parse_and_execute (command, (editing_mode == VI_EDITING_MODE) ? "v" : "C-xC-e", SEVAL_NOHIST);
restore_parser_state (&ps);
/* if some kind of reset_parser was called, undo it. */
reset_readahead_token ();
/* restore needed bash state */
if (reading_from_tty == 0)
{
restore_parser_state (&ps);
if (rl_prep_term_function)
(*rl_prep_term_function) (metaflag);
rl_set_signals ();
/* if some kind of reset_parser was called, undo it. */
reset_readahead_token ();
current_command_line_count = saved_command_line_count;
}
current_command_line_count = saved_command_line_count;
/* restore needed readline state */
if (reading_from_tty == 0)
{
if (rl_prep_term_function)
(*rl_prep_term_function) (metaflag);
rl_set_signals ();
/* Now erase the contents of the current line and undo the effects of the
rl_accept_line() above. We don't even want to make the text we just
executed available for undoing. */
rl_line_buffer[0] = '\0'; /* XXX */
rl_point = rl_end = 0;
rl_done = 0;
rl_readline_state = rrs;
/* Now erase the contents of the current line and undo the effects of the
rl_accept_line() above. We don't even want to make the text we just
executed available for undoing. */
rl_line_buffer[0] = '\0'; /* XXX */
rl_point = rl_end = 0;
rl_done = 0;
rl_readline_state = rrs;
#if defined (VI_MODE)
if (editing_mode == VI_EDITING_MODE)
rl_vi_insertion_mode (1, c);
if (editing_mode == VI_EDITING_MODE)
rl_vi_insertion_mode (1, c);
#endif
rl_forced_update_display ();
rl_forced_update_display ();
return r;
}
return r;
/* We are running interactively and reading from the keyboard. We need
to jump back to the top level after resetting enough state to read the
next command with readline. We call reset_parser() just in case. */
reset_parser ();
clear_shell_input_line (); /* XXX - probably not necessary */
/* The prompt strings will be reset by prompt_again() */
jump_to_top_level (REINIT);
}
#if defined (VI_MODE)
+2
View File
@@ -421,6 +421,7 @@ parse_and_execute (char *string, const char *from_file, int flags)
goto out;
case DISCARD:
case REINIT:
if (command)
run_unwind_frame ("pe_dispose");
last_result = last_command_exit_value = EXECUTION_FAILURE; /* XXX */
@@ -683,6 +684,7 @@ parse_string (char *string, const char *from_file, int flags, COMMAND **cmdp, ch
case EXITPROG:
case EXITBLTIN:
case DISCARD: /* XXX */
case REINIT:
if (command)
dispose_command (command);
/* Remember to call longjmp (top_level) after the old
+31 -13
View File
@@ -1,7 +1,7 @@
This file is fc.def, from which is created fc.c.
It implements the builtin "fc" in Bash.
Copyright (C) 1987-2024 Free Software Foundation, Inc.
Copyright (C) 1987-2025 Free Software Foundation, Inc.
This file is part of GNU Bash, the Bourne Again SHell.
@@ -23,7 +23,7 @@ $PRODUCES fc.c
$BUILTIN fc
$FUNCTION fc_builtin
$DEPENDS_ON HISTORY
$SHORT_DOC fc [-e ename] [-lnr] [first] [last] or fc -s [pat=rep] [command]
$SHORT_DOC fc [-e ename] [-D] [-lnr] [first] [last] or fc -s [pat=rep] [command]
Display or execute commands from the history list.
fc is used to list or edit and re-execute commands from the history list.
@@ -33,8 +33,11 @@ string.
Options:
-e ENAME select which editor to use. Default is FCEDIT, then EDITOR,
then vi
-l list lines instead of editing
then vi.
-D when editing and re-executing commands, fc removes the selected
commands from the history list before executing the edited
commands
-l list lines instead of editing
-n omit line numbers when listing
-r reverse the order of the lines (newest listed first)
@@ -113,15 +116,16 @@ extern int suppress_debug_trap_verbose;
/* fc builtin command (fix command) for Bash for those who
like K*rn-style history better than csh-style.
fc [-e ename] [-nlr] [first] [last]
fc [-e ename [-D]] [-nlr] [first] [last]
FIRST and LAST can be numbers specifying the range, or FIRST can be
a string, which means the most recent command beginning with that
string.
-e ENAME selects which editor to use. Default is FCEDIT, then EDITOR,
then the editor which corresponds to the current readline editing
mode, then vi.
then vi.
-D means to remove the selected commands from the history before
adding the edited ones.
-l means list lines instead of editing.
-n means no line numbers listed.
@@ -193,7 +197,7 @@ fc_builtin (WORD_LIST *list)
{
register int i;
register char *sep;
int numbering, reverse, listing, execute;
int numbering, reverse, listing, execute, delete_last;
int histbeg, histend, last_hist, retval, opt, rh, real_last;
FILE *stream;
REPL *rlist, *rl;
@@ -202,14 +206,14 @@ fc_builtin (WORD_LIST *list)
char *fn;
numbering = 1;
reverse = listing = execute = 0;
reverse = listing = execute = delete_last = 0;
ename = (char *)NULL;
/* Parse out the options and set which of the two forms we're in. */
reset_internal_getopt ();
lcurrent = list; /* XXX */
while (fc_number (loptend = lcurrent) == 0 &&
(opt = internal_getopt (list, ":e:lnrs")) != -1)
(opt = internal_getopt (list, ":e:Dlnrs")) != -1)
{
switch (opt)
{
@@ -233,6 +237,10 @@ fc_builtin (WORD_LIST *list)
ename = list_optarg;
break;
case 'D':
delete_last = 1;
break;
CASE_HELPOPT;
default:
builtin_usage ();
@@ -518,10 +526,20 @@ fc_builtin (WORD_LIST *list)
#if defined (READLINE)
/* If we're executing as part of a dispatched readline command like
{emacs,vi}_edit_and_execute_command, the readline state will indicate it.
We could remove the partial command from the history, but ksh93 doesn't
so we stay compatible. */
{emacs,vi}_edit_and_execute_command, the readline state will indicate it. */
#endif
/* If -D is supplied, we remove the selected commands from the history.
If we are being run by edit_and_execute_command, we want to remove the
partial command from the history so a HISTCONTROL value of `ignoredups'
doesn't cause the edited command to be skipped if the first lines are
identical. */
if (delete_last)
{
if (histbeg == histend)
bash_delete_histent (histbeg);
else
bash_delete_history_range (histbeg, histend);
}
/* Make sure parse_and_execute doesn't turn this off, even though a
call to parse_and_execute farther up the function call stack (e.g.,
+760 -757
View File
File diff suppressed because it is too large Load Diff
+10 -3
View File
@@ -5,7 +5,7 @@
.\" Case Western Reserve University
.\" chet.ramey@case.edu
.\"
.\" Last Change: Tue Dec 2 16:43:36 EST 2025
.\" Last Change: Thu Dec 18 17:18:21 EST 2025
.\"
.\" For bash_builtins, strip all but "SHELL BUILTIN COMMANDS" section
.\" For rbash, strip all but "RESTRICTED SHELL" section
@@ -22,7 +22,7 @@
.ds zX \" empty
.if \n(zZ=1 .ig zZ
.if \n(zY=1 .ig zY
.TH BASH 1 "2025 December 2" "GNU Bash 5.3"
.TH BASH 1 "2025 December 18" "GNU Bash 5.3"
.\"
.ie \n(.g \{\
.ds ' \(aq
@@ -10340,7 +10340,7 @@ that is not a function.
\fBfalse\fP
Does nothing; returns a non-zero status.
.TP
\fBfc\fP [\fB\-e\fP \fIename\fP] [\fB\-lnr\fP] [\fIfirst\fP] [\fIlast\fP]
\fBfc\fP [\fB\-e\fP \fIename\fP] [\fB\-D\fP] [\fB\-lnr\fP] [\fIfirst\fP] [\fIlast\fP]
.PD 0
.TP
\fBfc\fP \fB\-s\fP [\fIpat\fP=\fIrep\fP] [\fIcmd\fP]
@@ -10407,6 +10407,13 @@ If neither variable is set, \fBfc\fP uses
.FN vi.
When editing is complete, \fBfc\fP reads the file containing
the edited commands and echoes and executes them.
The
.B \-D
option, if supplied,
causes \fBfc\fP to remove the selected commands from the history
list before executing the file of edited commands.
.B \-D
is only active when \fBfc\fP is invoked in this way.
.IP
In the second form, \fBfc\fP re-executes \fIcommand\fP
after replacing each instance of \fIpat\fP with \fIrep\fP.
+144 -139
View File
@@ -1,9 +1,9 @@
This is bash.info, produced by makeinfo version 7.2 from bashref.texi.
This text is a brief description of the features that are present in the
Bash shell (version 5.3, 2 December 2025).
Bash shell (version 5.3, 18 December 2025).
This is Edition 5.3, last updated 2 December 2025, of The GNU Bash
This is Edition 5.3, last updated 18 December 2025, of The GNU Bash
Reference Manual, for Bash, Version 5.3.
Copyright © 1988-2025 Free Software Foundation, Inc.
@@ -26,10 +26,10 @@ Bash Features
*************
This text is a brief description of the features that are present in the
Bash shell (version 5.3, 2 December 2025). The Bash home page is
Bash shell (version 5.3, 18 December 2025). The Bash home page is
<http://www.gnu.org/software/bash/>.
This is Edition 5.3, last updated 2 December 2025, of The GNU Bash
This is Edition 5.3, last updated 18 December 2025, of The GNU Bash
Reference Manual, for Bash, Version 5.3.
Bash contains features that appear in other popular shells, and some
@@ -10962,7 +10962,7 @@ Bash provides two builtin commands which manipulate the history list and
history file.
fc
fc [-e ENAME] [-lnr] [FIRST] [LAST]
fc [-e ENAME] [-D] [-lnr] [FIRST] [LAST]
fc -s [PAT=REP] [COMMAND]
The first form selects a range of commands from FIRST to LAST from
@@ -10991,7 +10991,12 @@ history file.
FCEDIT variable if set, or the value of the EDITOR variable if
that is set, or vi if neither is set. When editing is complete,
fc reads the file of edited commands and echoes and executes
them.
them. The -D option, if supplied, causes fc to remove the
selected commands from the history list before executing the file
of edited commands. -D is only active when fc is invoked in
this way. It could be used if you make a typo in a command and
want to fix it using an editor while removing the erroneous command
from the history to avoid clutter.
In the second form, fc re-executes COMMAND after replacing each
instance of PAT in the selected command with REP. COMMAND is
@@ -12950,7 +12955,7 @@ D.1 Index of Shell Builtin Commands
(line 233)
* help: Bash Builtins. (line 375)
* history: Bash History Builtins.
(line 59)
(line 64)
* jobs: Job Control Builtins.
(line 28)
* kill: Job Control Builtins.
@@ -13676,138 +13681,138 @@ D.5 Concept Index

Tag Table:
Node: Top899
Node: Introduction2838
Node: What is Bash?3051
Node: What is a shell?4184
Node: Definitions6794
Node: Basic Shell Features10121
Node: Shell Syntax11345
Node: Shell Operation12372
Node: Quoting13663
Node: Escape Character15001
Node: Single Quotes15536
Node: Double Quotes15885
Node: ANSI-C Quoting17230
Node: Locale Translation18624
Node: Creating Internationalized Scripts20027
Node: Comments24225
Node: Shell Commands24992
Node: Reserved Words25931
Node: Simple Commands27074
Node: Pipelines27736
Node: Lists30992
Node: Compound Commands32912
Node: Looping Constructs33921
Node: Conditional Constructs36470
Node: Command Grouping51607
Node: Coprocesses53099
Node: GNU Parallel55785
Node: Shell Functions56703
Node: Shell Parameters65151
Node: Positional Parameters70052
Node: Special Parameters71142
Node: Shell Expansions74603
Node: Brace Expansion76792
Node: Tilde Expansion80128
Node: Shell Parameter Expansion83083
Node: Command Substitution103730
Node: Arithmetic Expansion107259
Node: Process Substitution108435
Node: Word Splitting109543
Node: Filename Expansion111987
Node: Pattern Matching115211
Node: Quote Removal120977
Node: Redirections121281
Node: Executing Commands131537
Node: Simple Command Expansion132204
Node: Command Search and Execution134312
Node: Command Execution Environment136756
Node: Environment140204
Node: Exit Status142107
Node: Signals144166
Node: Shell Scripts149114
Node: Shell Builtin Commands152412
Node: Bourne Shell Builtins154753
Node: Bash Builtins181472
Node: Modifying Shell Behavior219208
Node: The Set Builtin219550
Node: The Shopt Builtin231544
Node: Special Builtins248597
Node: Shell Variables249586
Node: Bourne Shell Variables250020
Node: Bash Variables252528
Node: Bash Features291812
Node: Invoking Bash292826
Node: Bash Startup Files299410
Node: Interactive Shells304652
Node: What is an Interactive Shell?305060
Node: Is this Shell Interactive?305722
Node: Interactive Shell Behavior306546
Node: Bash Conditional Expressions310307
Node: Shell Arithmetic315724
Node: Aliases319051
Node: Arrays322185
Node: The Directory Stack329888
Node: Directory Stack Builtins330685
Node: Controlling the Prompt335130
Node: The Restricted Shell338014
Node: Bash POSIX Mode340896
Node: Shell Compatibility Mode359843
Node: Job Control368850
Node: Job Control Basics369307
Node: Job Control Builtins375675
Node: Job Control Variables382463
Node: Command Line Editing383694
Node: Introduction and Notation385397
Node: Readline Interaction387749
Node: Readline Bare Essentials388937
Node: Readline Movement Commands390745
Node: Readline Killing Commands391741
Node: Readline Arguments393764
Node: Searching394854
Node: Readline Init File397097
Node: Readline Init File Syntax398400
Node: Conditional Init Constructs425351
Node: Sample Init File429736
Node: Bindable Readline Commands432856
Node: Commands For Moving434394
Node: Commands For History436858
Node: Commands For Text442249
Node: Commands For Killing446374
Node: Numeric Arguments449162
Node: Commands For Completion450314
Node: Keyboard Macros456010
Node: Miscellaneous Commands456711
Node: Readline vi Mode463278
Node: Programmable Completion464255
Node: Programmable Completion Builtins473991
Node: A Programmable Completion Example485728
Node: Using History Interactively491073
Node: Bash History Facilities491754
Node: Bash History Builtins495489
Node: History Interaction501960
Node: Event Designators506910
Node: Word Designators508488
Node: Modifiers510880
Node: Installing Bash512817
Node: Basic Installation513933
Node: Compilers and Options517809
Node: Compiling For Multiple Architectures518559
Node: Installation Names520312
Node: Specifying the System Type522546
Node: Sharing Defaults523292
Node: Operation Controls524006
Node: Optional Features525025
Node: Reporting Bugs537748
Node: Major Differences From The Bourne Shell539105
Node: GNU Free Documentation License560532
Node: Indexes585709
Node: Builtin Index586160
Node: Reserved Word Index593258
Node: Variable Index595703
Node: Function Index613116
Node: Concept Index627111
Node: Top901
Node: Introduction2842
Node: What is Bash?3055
Node: What is a shell?4188
Node: Definitions6798
Node: Basic Shell Features10125
Node: Shell Syntax11349
Node: Shell Operation12376
Node: Quoting13667
Node: Escape Character15005
Node: Single Quotes15540
Node: Double Quotes15889
Node: ANSI-C Quoting17234
Node: Locale Translation18628
Node: Creating Internationalized Scripts20031
Node: Comments24229
Node: Shell Commands24996
Node: Reserved Words25935
Node: Simple Commands27078
Node: Pipelines27740
Node: Lists30996
Node: Compound Commands32916
Node: Looping Constructs33925
Node: Conditional Constructs36474
Node: Command Grouping51611
Node: Coprocesses53103
Node: GNU Parallel55789
Node: Shell Functions56707
Node: Shell Parameters65155
Node: Positional Parameters70056
Node: Special Parameters71146
Node: Shell Expansions74607
Node: Brace Expansion76796
Node: Tilde Expansion80132
Node: Shell Parameter Expansion83087
Node: Command Substitution103734
Node: Arithmetic Expansion107263
Node: Process Substitution108439
Node: Word Splitting109547
Node: Filename Expansion111991
Node: Pattern Matching115215
Node: Quote Removal120981
Node: Redirections121285
Node: Executing Commands131541
Node: Simple Command Expansion132208
Node: Command Search and Execution134316
Node: Command Execution Environment136760
Node: Environment140208
Node: Exit Status142111
Node: Signals144170
Node: Shell Scripts149118
Node: Shell Builtin Commands152416
Node: Bourne Shell Builtins154757
Node: Bash Builtins181476
Node: Modifying Shell Behavior219212
Node: The Set Builtin219554
Node: The Shopt Builtin231548
Node: Special Builtins248601
Node: Shell Variables249590
Node: Bourne Shell Variables250024
Node: Bash Variables252532
Node: Bash Features291816
Node: Invoking Bash292830
Node: Bash Startup Files299414
Node: Interactive Shells304656
Node: What is an Interactive Shell?305064
Node: Is this Shell Interactive?305726
Node: Interactive Shell Behavior306550
Node: Bash Conditional Expressions310311
Node: Shell Arithmetic315728
Node: Aliases319055
Node: Arrays322189
Node: The Directory Stack329892
Node: Directory Stack Builtins330689
Node: Controlling the Prompt335134
Node: The Restricted Shell338018
Node: Bash POSIX Mode340900
Node: Shell Compatibility Mode359847
Node: Job Control368854
Node: Job Control Basics369311
Node: Job Control Builtins375679
Node: Job Control Variables382467
Node: Command Line Editing383698
Node: Introduction and Notation385401
Node: Readline Interaction387753
Node: Readline Bare Essentials388941
Node: Readline Movement Commands390749
Node: Readline Killing Commands391745
Node: Readline Arguments393768
Node: Searching394858
Node: Readline Init File397101
Node: Readline Init File Syntax398404
Node: Conditional Init Constructs425355
Node: Sample Init File429740
Node: Bindable Readline Commands432860
Node: Commands For Moving434398
Node: Commands For History436862
Node: Commands For Text442253
Node: Commands For Killing446378
Node: Numeric Arguments449166
Node: Commands For Completion450318
Node: Keyboard Macros456014
Node: Miscellaneous Commands456715
Node: Readline vi Mode463282
Node: Programmable Completion464259
Node: Programmable Completion Builtins473995
Node: A Programmable Completion Example485732
Node: Using History Interactively491077
Node: Bash History Facilities491758
Node: Bash History Builtins495493
Node: History Interaction502365
Node: Event Designators507315
Node: Word Designators508893
Node: Modifiers511285
Node: Installing Bash513222
Node: Basic Installation514338
Node: Compilers and Options518214
Node: Compiling For Multiple Architectures518964
Node: Installation Names520717
Node: Specifying the System Type522951
Node: Sharing Defaults523697
Node: Operation Controls524411
Node: Optional Features525430
Node: Reporting Bugs538153
Node: Major Differences From The Bourne Shell539510
Node: GNU Free Documentation License560937
Node: Indexes586114
Node: Builtin Index586565
Node: Reserved Word Index593663
Node: Variable Index596108
Node: Function Index613521
Node: Concept Index627516

End Tag Table
+144 -139
View File
@@ -2,9 +2,9 @@ This is bashref.info, produced by makeinfo version 7.2 from
bashref.texi.
This text is a brief description of the features that are present in the
Bash shell (version 5.3, 2 December 2025).
Bash shell (version 5.3, 18 December 2025).
This is Edition 5.3, last updated 2 December 2025, of The GNU Bash
This is Edition 5.3, last updated 18 December 2025, of The GNU Bash
Reference Manual, for Bash, Version 5.3.
Copyright © 1988-2025 Free Software Foundation, Inc.
@@ -27,10 +27,10 @@ Bash Features
*************
This text is a brief description of the features that are present in the
Bash shell (version 5.3, 2 December 2025). The Bash home page is
Bash shell (version 5.3, 18 December 2025). The Bash home page is
<http://www.gnu.org/software/bash/>.
This is Edition 5.3, last updated 2 December 2025, of The GNU Bash
This is Edition 5.3, last updated 18 December 2025, of The GNU Bash
Reference Manual, for Bash, Version 5.3.
Bash contains features that appear in other popular shells, and some
@@ -10963,7 +10963,7 @@ Bash provides two builtin commands which manipulate the history list and
history file.
fc
fc [-e ENAME] [-lnr] [FIRST] [LAST]
fc [-e ENAME] [-D] [-lnr] [FIRST] [LAST]
fc -s [PAT=REP] [COMMAND]
The first form selects a range of commands from FIRST to LAST from
@@ -10992,7 +10992,12 @@ history file.
FCEDIT variable if set, or the value of the EDITOR variable if
that is set, or vi if neither is set. When editing is complete,
fc reads the file of edited commands and echoes and executes
them.
them. The -D option, if supplied, causes fc to remove the
selected commands from the history list before executing the file
of edited commands. -D is only active when fc is invoked in
this way. It could be used if you make a typo in a command and
want to fix it using an editor while removing the erroneous command
from the history to avoid clutter.
In the second form, fc re-executes COMMAND after replacing each
instance of PAT in the selected command with REP. COMMAND is
@@ -12951,7 +12956,7 @@ D.1 Index of Shell Builtin Commands
(line 233)
* help: Bash Builtins. (line 375)
* history: Bash History Builtins.
(line 59)
(line 64)
* jobs: Job Control Builtins.
(line 28)
* kill: Job Control Builtins.
@@ -13677,138 +13682,138 @@ D.5 Concept Index

Tag Table:
Node: Top902
Node: Introduction2844
Node: What is Bash?3060
Node: What is a shell?4196
Node: Definitions6809
Node: Basic Shell Features10139
Node: Shell Syntax11366
Node: Shell Operation12396
Node: Quoting13690
Node: Escape Character15031
Node: Single Quotes15569
Node: Double Quotes15921
Node: ANSI-C Quoting17269
Node: Locale Translation18666
Node: Creating Internationalized Scripts20072
Node: Comments24273
Node: Shell Commands25043
Node: Reserved Words25985
Node: Simple Commands27131
Node: Pipelines27796
Node: Lists31055
Node: Compound Commands32978
Node: Looping Constructs33990
Node: Conditional Constructs36542
Node: Command Grouping51682
Node: Coprocesses53177
Node: GNU Parallel55866
Node: Shell Functions56787
Node: Shell Parameters65238
Node: Positional Parameters70142
Node: Special Parameters71235
Node: Shell Expansions74699
Node: Brace Expansion76891
Node: Tilde Expansion80230
Node: Shell Parameter Expansion83188
Node: Command Substitution103838
Node: Arithmetic Expansion107370
Node: Process Substitution108549
Node: Word Splitting109660
Node: Filename Expansion112107
Node: Pattern Matching115334
Node: Quote Removal121103
Node: Redirections121410
Node: Executing Commands131669
Node: Simple Command Expansion132339
Node: Command Search and Execution134450
Node: Command Execution Environment136897
Node: Environment140348
Node: Exit Status142254
Node: Signals144316
Node: Shell Scripts149267
Node: Shell Builtin Commands152568
Node: Bourne Shell Builtins154912
Node: Bash Builtins181634
Node: Modifying Shell Behavior219373
Node: The Set Builtin219718
Node: The Shopt Builtin231715
Node: Special Builtins248771
Node: Shell Variables249763
Node: Bourne Shell Variables250200
Node: Bash Variables252711
Node: Bash Features291998
Node: Invoking Bash293015
Node: Bash Startup Files299602
Node: Interactive Shells304847
Node: What is an Interactive Shell?305258
Node: Is this Shell Interactive?305923
Node: Interactive Shell Behavior306750
Node: Bash Conditional Expressions310514
Node: Shell Arithmetic315934
Node: Aliases319264
Node: Arrays322401
Node: The Directory Stack330107
Node: Directory Stack Builtins330907
Node: Controlling the Prompt335355
Node: The Restricted Shell338242
Node: Bash POSIX Mode341127
Node: Shell Compatibility Mode360077
Node: Job Control369087
Node: Job Control Basics369547
Node: Job Control Builtins375918
Node: Job Control Variables382709
Node: Command Line Editing383943
Node: Introduction and Notation385649
Node: Readline Interaction388004
Node: Readline Bare Essentials389195
Node: Readline Movement Commands391006
Node: Readline Killing Commands392005
Node: Readline Arguments394031
Node: Searching395124
Node: Readline Init File397370
Node: Readline Init File Syntax398676
Node: Conditional Init Constructs425630
Node: Sample Init File430018
Node: Bindable Readline Commands433141
Node: Commands For Moving434682
Node: Commands For History437149
Node: Commands For Text442543
Node: Commands For Killing446671
Node: Numeric Arguments449462
Node: Commands For Completion450617
Node: Keyboard Macros456316
Node: Miscellaneous Commands457020
Node: Readline vi Mode463590
Node: Programmable Completion464570
Node: Programmable Completion Builtins474309
Node: A Programmable Completion Example486049
Node: Using History Interactively491397
Node: Bash History Facilities492081
Node: Bash History Builtins495819
Node: History Interaction502293
Node: Event Designators507246
Node: Word Designators508827
Node: Modifiers511222
Node: Installing Bash513162
Node: Basic Installation514281
Node: Compilers and Options518160
Node: Compiling For Multiple Architectures518913
Node: Installation Names520669
Node: Specifying the System Type522906
Node: Sharing Defaults523655
Node: Operation Controls524372
Node: Optional Features525394
Node: Reporting Bugs538120
Node: Major Differences From The Bourne Shell539480
Node: GNU Free Documentation License560910
Node: Indexes586090
Node: Builtin Index586544
Node: Reserved Word Index593645
Node: Variable Index596093
Node: Function Index613509
Node: Concept Index627507
Node: Top904
Node: Introduction2848
Node: What is Bash?3064
Node: What is a shell?4200
Node: Definitions6813
Node: Basic Shell Features10143
Node: Shell Syntax11370
Node: Shell Operation12400
Node: Quoting13694
Node: Escape Character15035
Node: Single Quotes15573
Node: Double Quotes15925
Node: ANSI-C Quoting17273
Node: Locale Translation18670
Node: Creating Internationalized Scripts20076
Node: Comments24277
Node: Shell Commands25047
Node: Reserved Words25989
Node: Simple Commands27135
Node: Pipelines27800
Node: Lists31059
Node: Compound Commands32982
Node: Looping Constructs33994
Node: Conditional Constructs36546
Node: Command Grouping51686
Node: Coprocesses53181
Node: GNU Parallel55870
Node: Shell Functions56791
Node: Shell Parameters65242
Node: Positional Parameters70146
Node: Special Parameters71239
Node: Shell Expansions74703
Node: Brace Expansion76895
Node: Tilde Expansion80234
Node: Shell Parameter Expansion83192
Node: Command Substitution103842
Node: Arithmetic Expansion107374
Node: Process Substitution108553
Node: Word Splitting109664
Node: Filename Expansion112111
Node: Pattern Matching115338
Node: Quote Removal121107
Node: Redirections121414
Node: Executing Commands131673
Node: Simple Command Expansion132343
Node: Command Search and Execution134454
Node: Command Execution Environment136901
Node: Environment140352
Node: Exit Status142258
Node: Signals144320
Node: Shell Scripts149271
Node: Shell Builtin Commands152572
Node: Bourne Shell Builtins154916
Node: Bash Builtins181638
Node: Modifying Shell Behavior219377
Node: The Set Builtin219722
Node: The Shopt Builtin231719
Node: Special Builtins248775
Node: Shell Variables249767
Node: Bourne Shell Variables250204
Node: Bash Variables252715
Node: Bash Features292002
Node: Invoking Bash293019
Node: Bash Startup Files299606
Node: Interactive Shells304851
Node: What is an Interactive Shell?305262
Node: Is this Shell Interactive?305927
Node: Interactive Shell Behavior306754
Node: Bash Conditional Expressions310518
Node: Shell Arithmetic315938
Node: Aliases319268
Node: Arrays322405
Node: The Directory Stack330111
Node: Directory Stack Builtins330911
Node: Controlling the Prompt335359
Node: The Restricted Shell338246
Node: Bash POSIX Mode341131
Node: Shell Compatibility Mode360081
Node: Job Control369091
Node: Job Control Basics369551
Node: Job Control Builtins375922
Node: Job Control Variables382713
Node: Command Line Editing383947
Node: Introduction and Notation385653
Node: Readline Interaction388008
Node: Readline Bare Essentials389199
Node: Readline Movement Commands391010
Node: Readline Killing Commands392009
Node: Readline Arguments394035
Node: Searching395128
Node: Readline Init File397374
Node: Readline Init File Syntax398680
Node: Conditional Init Constructs425634
Node: Sample Init File430022
Node: Bindable Readline Commands433145
Node: Commands For Moving434686
Node: Commands For History437153
Node: Commands For Text442547
Node: Commands For Killing446675
Node: Numeric Arguments449466
Node: Commands For Completion450621
Node: Keyboard Macros456320
Node: Miscellaneous Commands457024
Node: Readline vi Mode463594
Node: Programmable Completion464574
Node: Programmable Completion Builtins474313
Node: A Programmable Completion Example486053
Node: Using History Interactively491401
Node: Bash History Facilities492085
Node: Bash History Builtins495823
Node: History Interaction502698
Node: Event Designators507651
Node: Word Designators509232
Node: Modifiers511627
Node: Installing Bash513567
Node: Basic Installation514686
Node: Compilers and Options518565
Node: Compiling For Multiple Architectures519318
Node: Installation Names521074
Node: Specifying the System Type523311
Node: Sharing Defaults524060
Node: Operation Controls524777
Node: Optional Features525799
Node: Reporting Bugs538525
Node: Major Differences From The Bourne Shell539885
Node: GNU Free Documentation License561315
Node: Indexes586495
Node: Builtin Index586949
Node: Reserved Word Index594050
Node: Variable Index596498
Node: Function Index613914
Node: Concept Index627912

End Tag Table
+2 -2
View File
@@ -2,10 +2,10 @@
Copyright (C) 1988-2025 Free Software Foundation, Inc.
@end ignore
@set LASTCHANGE Tue Dec 2 16:47:35 EST 2025
@set LASTCHANGE Thu Dec 18 17:25:09 EST 2025
@set EDITION 5.3
@set VERSION 5.3
@set UPDATED 2 December 2025
@set UPDATED 18 December 2025
@set UPDATED-MONTH December 2025
+1
View File
@@ -114,6 +114,7 @@ reader_loop (void)
alone. */
if (last_command_exit_value == 0)
set_exit_status (EXECUTION_FAILURE);
case REINIT:
if (subshell_environment)
{
current_command = (COMMAND *)NULL;
+8 -1
View File
@@ -154,7 +154,7 @@ history list and history file.
@item fc
@btindex fc
@example
@code{fc [-e @var{ename}] [-lnr] [@var{first}] [@var{last}]}
@code{fc [-e @var{ename}] [-D] [-lnr] [@var{first}] [@var{last}]}
@code{fc -s [@var{pat}=@var{rep}] [@var{command}]}
@end example
@@ -191,6 +191,13 @@ value of the @env{FCEDIT} variable if set, or the value of the
@env{EDITOR} variable if that is set, or @code{vi} if neither is set.
When editing is complete, @code{fc} reads the file of edited commands
and echoes and executes them.
The @option{-D} option, if supplied,
causes @code{fc} to remove the selected commands from the history
list before executing the file of edited commands.
@option{-D} is only active when @code{fc} is invoked in this way.
It could be used if you make a typo in a command and want to fix it using
an editor while removing the erroneous command from the history to
avoid clutter.
In the second form, @code{fc} re-executes @var{command} after
replacing each instance of @var{pat} in the selected command with @var{rep}.
+2
View File
@@ -1397,6 +1397,7 @@ run_wordexp (char *words)
case EXITBLTIN:
return last_command_exit_value;
case DISCARD:
case REINIT:
return last_command_exit_value = 1;
default:
command_error ("run_wordexp", CMDERR_BADJUMP, code, 0);
@@ -1475,6 +1476,7 @@ run_one_command (char *command)
case EXITBLTIN:
return last_command_exit_value;
case DISCARD:
case REINIT:
return last_command_exit_value = 1;
default:
command_error ("run_one_command", CMDERR_BADJUMP, code, 0);
+2 -2
View File
@@ -394,7 +394,7 @@ A star (*) next to a name means that the command is disabled.
exit [n] typeset [-aAfFgiIlnrtux] name[=value>
export [-fn] [name[=value] ...] or ex> ulimit [-SHabcdefiklmnpqrstuvxPRT] [>
false umask [-p] [-S] [mode]
fc [-e ename] [-lnr] [first] [last] o> unalias [-a] name [name ...]
fc [-e ename] [-D] [-lnr] [first] [la> unalias [-a] name [name ...]
fg [job_spec] unset [-f] [-v] [-n] [name ...]
for NAME [in WORDS ... ] ; do COMMAND> until COMMANDS; do COMMANDS-2; done
for (( exp1; exp2; exp3 )); do COMMAN> variables - Names and meanings of so>
@@ -487,7 +487,7 @@ A star (*) next to a name means that the command is disabled.
exit [n] typeset [-aAfFgiIlnrtux] name[=value>
export [-fn] [name[=value] ...] or ex> ulimit [-SHabcdefiklmnpqrstuvxPRT] [>
false umask [-p] [-S] [mode]
fc [-e ename] [-lnr] [first] [last] o> unalias [-a] name [name ...]
fc [-e ename] [-D] [-lnr] [first] [la> unalias [-a] name [name ...]
fg [job_spec] unset [-f] [-v] [-n] [name ...]
for NAME [in WORDS ... ] ; do COMMAND> until COMMANDS; do COMMANDS-2; done
for (( exp1; exp2; exp3 )); do COMMAN> variables - Names and meanings of so>
+1 -1
View File
@@ -2,7 +2,7 @@
history: usage: history [-c] [-d offset] [n] or history -anrw [filename] or history -ps arg [arg...]
./history.tests: line 21: history: cannot use more than one of -anrw
./history.tests: line 24: fc: -v: invalid option
fc: usage: fc [-e ename] [-lnr] [first] [last] or fc -s [pat=rep] [command]
fc: usage: fc [-e ename] [-D] [-lnr] [first] [last] or fc -s [pat=rep] [command]
1 for i in one two three; do echo $i; done
2 /bin/sh -c 'echo this is $0'
3 ls