bug-bash
[Top][All Lists]
Advanced

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

Re: edit-and-execute-command, history and PS1


From: Chet Ramey
Subject: Re: edit-and-execute-command, history and PS1
Date: Wed, 8 Jun 2016 11:25:44 -0400
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:45.0) Gecko/20100101 Thunderbird/45.1.1

On 6/2/16 11:28 AM, Jure Oder wrote:
> Dear all,
> 
> I have noticed strange behaviour if my PS1 variable contains "the history
> number of this command" (\!). When the prompt returns after invoking the
> edit-and-execute-command (C-xC-e) the history number is not increased. If I
> then press return, the history number is increased by two (or more,
> depending on how many lines(?) I entered with the editor). Also, if I then
> list the history, I notice that both, the part that was entered in the line
> before invoking (C-xC-e) and the part actually executed, are listed in
> history. The history number shown in the prompt before invoking C-xC-e
> refers to the partially constructed line (or empty, if nothing was
> entered). The actual history number I have to use to rerun the command is
> one higher.
> 
> I assume this is not the intended behaviour.

It is.  There are two questions here.

1.  Bash leaves the partial command that was fed to the editor in the
    history list for compatibility.  Other shells that implement this
    as part of line editing do the same.  Internally, it's because
    everyone uses the `fc' builtin as the engine to invoke the editor
    and run the resulting command file.

2.  The history number doesn't increase when the prompt is redisplayed
    because, from the shell's perspective, the line was not returned
    from readline for execution.  It's still the same editing and execution
    context.  When you enter newline, the prompt gets reevaluated, and
    the updated history number gets used.  The lines from the temp file
    that the editor saves are added to the history list because that's
    how Posix says to do it and how all the shells that implement this
    behave.

Chet

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    chet@case.edu    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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