On 2/20/22 11:38 AM, Andrea Monaco wrote:
on my bash 5.0.3, when I input
$ foo!\
I get "bash: !\: event not found", which I think is appropriate, but the
line doesn't get saved in history. The same doesn't happen for other
errors, for example "command not found".
Is this behavior intended?
Yes. History substitution isn't the same kind of error as a command not
found or word expansion error. As you discovered, it takes place before
any further history processing, like saving to the history list.
History substitution can be viewed as a line containing commands to
select and modify a previous history entry, not a separate line itself. If
those commands fail, why save them? So it's the line following history
expansion that gets saved to the history.
That means a history expansion failure has historically caused the line
to be immediately discarded, and not passed onto further processing stages.
If you want an opportunity to re-edit a failed history expansion, set the
`histreedit' shell option.
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU c...@case.edu http://tiswww.cwru.edu/~chet/