smallnow wrote: > $ echo $BASH_VERSION > 3.2.48(1)-release > $ echo $(fc -nl -1) > echo $BASH_VERSION > > > $ echo $BASH_VERSION > 4.0.10(2)-release > $ echo $(fc -nl -1) > echo $(fc -nl -1) > > I see there were a lot of changes to fc, is this intended or a bug?
The off-by-one errors that occurred when running fc in non-interactive contexts were fixed, but it's possible that the changes were too aggressive. There's no reason that `echo $(fc -nl -1)' and `fc -nl -1' shouldn't echo the same thing when run from the same shell -- command substitution should inherit the history settings and history list. See if the following patch fixes things for you. Chet -- ``The lyf so short, the craft so long to lerne.'' - Chaucer Chet Ramey, ITS, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/
*** ../bash-4.0-patched/builtins/fc.def 2009-01-04 14:32:22.000000000 -0500 --- builtins/fc.def 2009-03-21 14:03:43.000000000 -0400 *************** *** 89,92 **** --- 89,93 ---- extern int literal_history; extern int posixly_correct; + extern int subshell_environment, interactive_shell; extern int unlink __P((const char *)); *************** *** 173,177 **** register char *sep; int numbering, reverse, listing, execute; ! int histbeg, histend, last_hist, retval, opt; FILE *stream; REPL *rlist, *rl; --- 174,178 ---- register char *sep; int numbering, reverse, listing, execute; ! int histbeg, histend, last_hist, retval, opt, rh; FILE *stream; REPL *rlist, *rl; *************** *** 276,279 **** --- 277,282 ---- 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)); } *************** *** 294,298 **** so we check hist_last_line_added. */ ! last_hist = i - remember_on_history - hist_last_line_added; if (list) --- 297,306 ---- so we check 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) *************** *** 457,461 **** HIST_ENTRY **hlist; { ! int sign, n, clen; register int i, j; register char *s; --- 465,469 ---- HIST_ENTRY **hlist; { ! int sign, n, clen, rh; register int i, j; register char *s; *************** *** 473,477 **** 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; /* No specification defaults to most recent command. */ --- 481,490 ---- so we check hist_last_line_added. This needs to agree with the calculation of last_hist in fc_builtin above. */ ! /* 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. */