[gnu.bash.bug] history numbers are wrong

roland@AI.MIT.EDU (Roland McGrath) (06/21/89)

The history number displayed by \# in PS1 does not correspond
to the numbers used in ! history references or the `history' builtin.
The numbers given by \# start at 1 with each bash invocation,
while the real history numbers start at the beginning of .bash_history.

bfox@AUREL.CALTECH.EDU (Brian Fox) (06/21/89)

   From: roland@ai.mit.edu (Roland McGrath)
   Date: Wed, 21 Jun 89 12:59:59 JST

   The history number displayed by \# in PS1 does not correspond
   to the numbers used in ! history references or the `history' builtin.
   The numbers given by \# start at 1 with each bash invocation,
   while the real history numbers start at the beginning of .bash_history.

The number display by \# is not the history number.  Here is some text
from FEATURES:

	Here is the comment next to the decode_prompt_string function.

	/* Return a string which will be printed as a prompt.  The string
	   may contain special characters which are decoded as follows:

		\t	the time
		\d	the date
		\n	CRLF
		\s	the name of the shell
		\w	the current working directory
		\u	your username
		\h	the hostname
		\#	the command number of this command
		\<octal> character code in octal
		\\	a backslash
	*/

It appears that more than one person wants the behaviour of "\!" in csh.
However, I have been wondering about other possible ways of handling
prompt strings, including standard word evaluation of it.

Brian

thomas@helios.prosys.se (Thomas Thyberg) (06/22/89)

In article <8906210400.AA08380@hobbes.ai.mit.edu> roland@AI.MIT.EDU (Roland McGrath) writes:
>The history number displayed by \# in PS1 does not correspond
>to the numbers used in ! history references or the `history' builtin.
>The numbers given by \# start at 1 with each bash invocation,
>while the real history numbers start at the beginning of .bash_history.

This seems to fix that problem. I'm not sure this is the 'right' way of
fixing it, but it works.

*** history.c.orig	Tue Jun 13 12:03:19 1989
--- history.c	Thu Jun 15 12:52:03 1989
***************
*** 354,361 ****
  	line = (char *)xrealloc (line, line_size += TYPICAL_LINE_SIZE);
      }
      line[i] = '\0';
!     if (line[0])
        add_history (line);
    }
    free (line);
    fclose (file);
--- 354,364 ----
  	line = (char *)xrealloc (line, line_size += TYPICAL_LINE_SIZE);
      }
      line[i] = '\0';
!     if (line[0]) {
!       extern int current_command_number;
!       current_command_number++;
        add_history (line);
+     }
    }
    free (line);
    fclose (file);
-- 
Thomas Thyberg			INET : thomas@prosys.se
Programsystem AB		UUCP : ...!{uunet,mcvax}!sunic!prosys!thomas
Teknikringen 2A			PHONE: +46 (0)13 21 40 40
S-583 30 Linkoping, Sweden	FAX  : +46 (0)13 21 36 35

bfox@AUREL.CALTECH.EDU (Brian Fox) (06/23/89)

I guess I should say this since I never have:

I greatly appreciate the bug reports and fixes supplied by the various
members of this group, and my job would be infinitely more difficult
without all of your help.

However, unless I officially "bless" a patch presented in this mailing
list, you install the "fix" at your own risk.  The next version of bash
will be presented with diffs for .99 and also as a complete source tree,
so bash maintainers will be able to decide which is more convenient for
them to use.

Some of the patches are very good, and have found their way into the
next release; some of them are not as good, and have been discarded in
favor of a cleaner fix, or failing any cleaner fix, not implemented.

This is because I would rather let something minor remain broken than
break more things in a less compatible fashion by installing an unclean
fix.

Thanks for all your support,

	Brian Fox