bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Inconsistent results when history -s is used within PROMPT_COMMAND


From: Chet Ramey
Subject: Re: Inconsistent results when history -s is used within PROMPT_COMMAND
Date: Wed, 17 Jun 2009 07:58:09 -0400

> I'm sorry, I'm afraid I don't understand the following sentence:
> 
> history -s will not delete the previous history entry before pushing the 
> new entry if it's added to a previous entry as part of a compound command.

Readline (and the shell, really) works a line at a time.  When a line
is read, it's added to the history.  Conceptually, that's simple.  It
gets complicated when the line is part of a multi-line, such as a
quoted string that spans lines, or compound command, such as a for
loop, and command-oriented history is enabled.  In that case, bash
appends the line to the last history entry, so all lines of a
multi-line command are saved in the same history entry.  Bash tries to
do the right thing with multi-line commands and history -s, while
trying to figure out whether or not the history -s itself is already
in the history or the multi-line command was the last thing entered. 
In most cases, it does.  When the history -s is not entered at the
command line, but part of $PROMPT_COMMAND, bash knows that a
multi-line history entry was entered but can't tell whether or not the
entry is complete and safe to remove, so it doesn't. 

It's possible that the check can be improved, but I'd rather have too
many history entries than remove one that should stay.

There are other cases when bash won't delete the last history entry when
`history -s' is used, such as when it was not added due to HISTIGNORE or
HISTCONTROL.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer

Chet Ramey, ITS, CWRU    chet@case.edu    http://tiswww.tis.case.edu/~chet/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]