Roman Rakus e73230
			     BASH PATCH REPORT
Roman Rakus e73230
			     =================
Roman Rakus e73230
Roman Rakus e73230
Bash-Release:	4.0
Roman Rakus e73230
Patch-ID:	bash40-014
Roman Rakus e73230
Roman Rakus e73230
Bug-Reported-by:	smallnow@gmail.com
Roman Rakus e73230
Bug-Reference-ID:	<49C460FE.40307@gmail.com>
Roman Rakus e73230
Bug-Reference-URL:	http://lists.gnu.org/archive/html/bug-bash/2009-03/msg00166.html
Roman Rakus e73230
Roman Rakus e73230
Bug-Description:
Roman Rakus e73230
Roman Rakus e73230
When the fc builtin is run in a command substitution from a shell with history
Roman Rakus e73230
enabled, it does not correctly calculate the command on which to operate.
Roman Rakus e73230
Roman Rakus e73230
Patch:
Roman Rakus e73230
Roman Rakus e73230
*** ../bash-4.0-patched/builtins/fc.def	2009-01-04 14:32:22.000000000 -0500
Roman Rakus e73230
--- builtins/fc.def	2009-03-21 14:03:43.000000000 -0400
Roman Rakus e73230
***************
Roman Rakus e73230
*** 89,92 ****
Roman Rakus e73230
--- 89,93 ----
Roman Rakus e73230
  extern int literal_history;
Roman Rakus e73230
  extern int posixly_correct;
Roman Rakus e73230
+ extern int subshell_environment, interactive_shell;
Roman Rakus e73230
  
Roman Rakus e73230
  extern int unlink __P((const char *));
Roman Rakus e73230
***************
Roman Rakus e73230
*** 173,177 ****
Roman Rakus e73230
    register char *sep;
Roman Rakus e73230
    int numbering, reverse, listing, execute;
Roman Rakus e73230
!   int histbeg, histend, last_hist, retval, opt;
Roman Rakus e73230
    FILE *stream;
Roman Rakus e73230
    REPL *rlist, *rl;
Roman Rakus e73230
--- 174,178 ----
Roman Rakus e73230
    register char *sep;
Roman Rakus e73230
    int numbering, reverse, listing, execute;
Roman Rakus e73230
!   int histbeg, histend, last_hist, retval, opt, rh;
Roman Rakus e73230
    FILE *stream;
Roman Rakus e73230
    REPL *rlist, *rl;
Roman Rakus e73230
***************
Roman Rakus e73230
*** 276,279 ****
Roman Rakus e73230
--- 277,282 ----
Roman Rakus e73230
        fprintf (stderr, "%s\n", command);
Roman Rakus e73230
        fc_replhist (command);	/* replace `fc -s' with command */
Roman Rakus e73230
+       /* Posix says that the re-executed commands should be entered into the
Roman Rakus e73230
+ 	 history. */
Roman Rakus e73230
        return (parse_and_execute (command, "fc", SEVAL_NOHIST));
Roman Rakus e73230
      }
Roman Rakus e73230
***************
Roman Rakus e73230
*** 294,298 ****
Roman Rakus e73230
       so we check hist_last_line_added. */
Roman Rakus e73230
  
Roman Rakus e73230
!   last_hist = i - remember_on_history - hist_last_line_added;
Roman Rakus e73230
  
Roman Rakus e73230
    if (list)
Roman Rakus e73230
--- 297,306 ----
Roman Rakus e73230
       so we check hist_last_line_added. */
Roman Rakus e73230
  
Roman Rakus e73230
!   /* Even though command substitution through parse_and_execute turns off
Roman Rakus e73230
!      remember_on_history, command substitution in a shell when set -o history
Roman Rakus e73230
!      has been enabled (interactive or not) should use it in the last_hist
Roman Rakus e73230
!      calculation as if it were on. */
Roman Rakus e73230
!   rh = remember_on_history || ((subshell_environment & SUBSHELL_COMSUB) && enable_history_list);
Roman Rakus e73230
!   last_hist = i - rh - hist_last_line_added;
Roman Rakus e73230
  
Roman Rakus e73230
    if (list)
Roman Rakus e73230
***************
Roman Rakus e73230
*** 457,461 ****
Roman Rakus e73230
       HIST_ENTRY **hlist;
Roman Rakus e73230
  {
Roman Rakus e73230
!   int sign, n, clen;
Roman Rakus e73230
    register int i, j;
Roman Rakus e73230
    register char *s;
Roman Rakus e73230
--- 465,469 ----
Roman Rakus e73230
       HIST_ENTRY **hlist;
Roman Rakus e73230
  {
Roman Rakus e73230
!   int sign, n, clen, rh;
Roman Rakus e73230
    register int i, j;
Roman Rakus e73230
    register char *s;
Roman Rakus e73230
***************
Roman Rakus e73230
*** 473,477 ****
Roman Rakus e73230
       so we check hist_last_line_added.  This needs to agree with the
Roman Rakus e73230
       calculation of last_hist in fc_builtin above. */
Roman Rakus e73230
!   i -= remember_on_history + hist_last_line_added;
Roman Rakus e73230
  
Roman Rakus e73230
    /* No specification defaults to most recent command. */
Roman Rakus e73230
--- 481,490 ----
Roman Rakus e73230
       so we check hist_last_line_added.  This needs to agree with the
Roman Rakus e73230
       calculation of last_hist in fc_builtin above. */
Roman Rakus e73230
!   /* Even though command substitution through parse_and_execute turns off
Roman Rakus e73230
!      remember_on_history, command substitution in a shell when set -o history
Roman Rakus e73230
!      has been enabled (interactive or not) should use it in the last_hist
Roman Rakus e73230
!      calculation as if it were on. */
Roman Rakus e73230
!   rh = remember_on_history || ((subshell_environment & SUBSHELL_COMSUB) && enable_history_list);
Roman Rakus e73230
!   i -= rh + hist_last_line_added;
Roman Rakus e73230
  
Roman Rakus e73230
    /* No specification defaults to most recent command. */
Roman Rakus e73230
*** ../bash-4.0/patchlevel.h	2009-01-04 14:32:40.000000000 -0500
Roman Rakus e73230
--- patchlevel.h	2009-02-22 16:11:31.000000000 -0500
Roman Rakus e73230
***************
Roman Rakus e73230
*** 26,30 ****
Roman Rakus e73230
     looks for to find the patch level (for the sccs version string). */
Roman Rakus e73230
  
Roman Rakus e73230
! #define PATCHLEVEL 13
Roman Rakus e73230
  
Roman Rakus e73230
  #endif /* _PATCHLEVEL_H_ */
Roman Rakus e73230
--- 26,30 ----
Roman Rakus e73230
     looks for to find the patch level (for the sccs version string). */
Roman Rakus e73230
  
Roman Rakus e73230
! #define PATCHLEVEL 14
Roman Rakus e73230
  
Roman Rakus e73230
  #endif /* _PATCHLEVEL_H_ */