bug-bash
[Top][All Lists]
Advanced

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

Re: Quoted multiline command interpreted by history as separate commands


From: Chet Ramey
Subject: Re: Quoted multiline command interpreted by history as separate commands
Date: Mon, 28 Dec 2015 14:53:49 -0500
User-agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.10; rv:38.0) Gecko/20100101 Thunderbird/38.4.0

On 12/26/15 6:15 PM, james harvey wrote:

> It appears bash sends an executed quoted multiline command to the
> in-memory history list as one command.

Yes.  The history file, through readline-6.3, is completely line-based.
The history library assumes that each line in the history file is a single
history entry, with an accompanying optional timestamp, and treats the
history file as such when it reads it.

The history library makes few assumptions about the entries in the
history file.  It's quite possible for an application that uses that
file to enable history timestamps, append to the history file, and
later append commands to the same file (possibly in a different
session) without timestamps, so it only assumes that a timestamp
applies to the immediately following line.

> But, it appears bash when parsing .bash_history is unable to
> distinguish quoted multiline commands from separate commands, and
> reads them into the in-memory history list separately.  Doing so, if
> the user is using history timestamps, it appears to properly use the
> timestamp for the first line, and improperly use the modified
> timestamp on the .bash_history for subsequent lines.

History file lines without an accompanying timestamp get the current time.

I have code that will go into the devel branch that handles the
multi-line entry case.

It uses a heuristic: if the application has indicated that it wants to
use timestamps (in bash's case, this means setting HISTTIMEFORMAT) and
the first line in the history file looks like a timestamp, the history
library assumes that timestamps appear consistently throughout the
history file and uses them to delimit commands.  This will break in the
case I describe above, but I think that's rare enough to at least leave
multiline history entry support enabled during development.  We'll see
how it goes.  I'm willing to delay the release of bash-4.4 to get
enough testing for this.

-- 
``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]