diff options
author | Chet Ramey <chet.ramey@case.edu> | 2011-11-21 20:49:12 -0500 |
---|---|---|
committer | Chet Ramey <chet.ramey@case.edu> | 2011-11-21 20:49:12 -0500 |
commit | 89a92869e56aba4e4cab2d639c00a86f0545c862 (patch) | |
tree | e1cd4da50318af8ab1f3141d39d4b0b8e1e7c500 /builtins/fc.def | |
parent | 17345e5ad288f7543b77b23a25aa380eacc279f2 (diff) | |
download | bash-89a92869e56aba4e4cab2d639c00a86f0545c862.tar.gz |
Bash-4.0 patchlevel 38bash-4.0.38bash-4.0
Diffstat (limited to 'builtins/fc.def')
-rw-r--r-- | builtins/fc.def | 21 |
1 files changed, 17 insertions, 4 deletions
diff --git a/builtins/fc.def b/builtins/fc.def index 22425d70..a378d9de 100644 --- a/builtins/fc.def +++ b/builtins/fc.def @@ -88,6 +88,7 @@ extern int errno; extern int current_command_line_count; extern int literal_history; extern int posixly_correct; +extern int subshell_environment, interactive_shell; extern int unlink __P((const char *)); @@ -172,7 +173,7 @@ fc_builtin (list) register int i; register char *sep; int numbering, reverse, listing, execute; - int histbeg, histend, last_hist, retval, opt; + int histbeg, histend, last_hist, retval, opt, rh; FILE *stream; REPL *rlist, *rl; char *ename, *command, *newcom, *fcedit; @@ -275,6 +276,8 @@ fc_builtin (list) fprintf (stderr, "%s\n", command); fc_replhist (command); /* replace `fc -s' with command */ + /* Posix says that the re-executed commands should be entered into the + history. */ return (parse_and_execute (command, "fc", SEVAL_NOHIST)); } @@ -293,7 +296,12 @@ fc_builtin (list) line was actually added (HISTIGNORE may have caused it to not be), so we check hist_last_line_added. */ - last_hist = i - remember_on_history - hist_last_line_added; + /* Even though command substitution through parse_and_execute turns off + remember_on_history, command substitution in a shell when set -o history + has been enabled (interactive or not) should use it in the last_hist + calculation as if it were on. */ + rh = remember_on_history || ((subshell_environment & SUBSHELL_COMSUB) && enable_history_list); + last_hist = i - rh - hist_last_line_added; if (list) { @@ -456,7 +464,7 @@ fc_gethnum (command, hlist) char *command; HIST_ENTRY **hlist; { - int sign, n, clen; + int sign, n, clen, rh; register int i, j; register char *s; @@ -472,7 +480,12 @@ fc_gethnum (command, hlist) line was actually added (HISTIGNORE may have caused it to not be), so we check hist_last_line_added. This needs to agree with the calculation of last_hist in fc_builtin above. */ - i -= remember_on_history + hist_last_line_added; + /* Even though command substitution through parse_and_execute turns off + remember_on_history, command substitution in a shell when set -o history + has been enabled (interactive or not) should use it in the last_hist + calculation as if it were on. */ + rh = remember_on_history || ((subshell_environment & SUBSHELL_COMSUB) && enable_history_list); + i -= rh + hist_last_line_added; /* No specification defaults to most recent command. */ if (command == NULL) |