2

I've found a behavior in bash (or is it readline?) that I cannot explain. After invoking the edit-and-execute-command Readline command, the debug trap's command is printed prior to execution. Is this a bug?

Here's how to reproduce the issue with a default bash install (no dotfiles besides those in /etc, and it happens on Linux and macOS with all the versionf of bash I could find):

bash-5.0$ trap date DEBUG
bash-5.0$ echo hi
Fri May  1 23:07:38 PDT 2020
hi
bash-5.0$ echo hi

At this point, type Control-X Control-E. The editor opens. Exit the editor. This is what you see next:

echo hi
date
Fri May  1 23:07:47 PDT 2020
hi
bash-5.0$ echo hi

My question is if there's any good reason for the shell to print date after exiting the editor.

The reason this is a problem for me is that I use the debug trap to run a command after the user enters a command but before it runs for iTerm2's shell integration using https://github.com/rcaloras/bash-preexec. AFAIK there is no other way to do this in bash (though I'm open to alternatives!)

For context, it originally came up here: https://gitlab.com/gnachman/iterm2/-/issues/8808#note_331367916

1 Answer 1

1

I got lucky and found an almost satisfying answer in the bash source code. It's detailed here: https://gitlab.com/gnachman/iterm2/-/issues/8808#note_335276685

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.