I'm running a larger one-line command. It is unexpectedly outputting (twice per iteration) the following:

__bp_preexec_invoke_exec "$_"

Here is the pared down command (removed other activity in loop):

for i in `seq 1 3`; do sleep .1 ; done

note: after i have played with this a few times it inexplicably stops printing the unexpected output

What I've tried

  • If I remove sleep .5 I do not get the unexpected output
  • If I simply run sleep .5 the prompt returns but there is no output
  • I have googled around for __bp_preexec_invoke_exec, but I am unable to determine how it applies to what I'm doing


What is __bp_preexec_invoke_exec "$_"?

How can I run this without the unwanted output?

More info on solution thanks to @gina2x:

Here is the output of declare -f | grep preexec

__bp_preexec_invoke_exec ()
    if [[ -z "$__bp_preexec_interactive_mode" ]]; then
    local preexec_function;
    local preexec_ret_value=0;
    for preexec_function in "${preexec_functions[@]}";
        if type -t "$preexec_function" > /dev/null; then
            $preexec_function "$this_command";
    __bp_set_ret_value "$preexec_ret_value" "$__bp_last_argument_prev_command"
    if [[ -z "${iterm2_ran_preexec:-}" ]]; then
        __iterm2_preexec "";
__iterm2_preexec ()

I see in there a lot of "iterm2" information (I'm on a Mac and using iTerm2.app).

In fact, when I try to reproduce using Terminal.app, I am unable to reproduce the unexpected output.

Excellent sleuthing with declare -f - thank you!

  • Have you tried the bash debugger -x like: bash -x -c 'for i in $(seq 3); do sleep .1 ; done'
    – hschou
    Commented Dec 26, 2017 at 16:30
  • @hschou i will try it; i did just try it, but it's stopped the output again. it's very strange.
    – WEBjuju
    Commented Dec 26, 2017 at 16:43
  • 2
    I bet you source some weird 3rd party script in .bashrc. Thus, first thing to try is run bash --norc --noprofile and repeat the exercise.
    – jimmij
    Commented Dec 26, 2017 at 17:11
  • @jimmij well, ~/.bashrc only has this: [[ "$-" != *i* ]] && return but i checked /etc/bashrc and while it also has a are we an interactive shell? section with a longer script, it seems to have come with centos (CentOS Linux release 7.4.1708 (Core)). the unexpected output only seems to show once and then not for some unknown time after; possibly changing the length of the sleep argument starts the output again, but since it does it and then doesn't, it's hard to scientifically apply the debugging ideas given so far. i'll keep trying.
    – WEBjuju
    Commented Dec 26, 2017 at 17:45

2 Answers 2


Seems like __bp_preexec_invoke_exec is part of https://github.com/rcaloras/bash-preexec/blob/master/bash-preexec.sh. And it seems like that there is a bug in that script.

That project adds 'preexec' functionality to bash by adding DEBUG trap, I did not test, but I can imagine that it might not work properly in the way you see it. Check if it is installed in you environment - you could do so by declare -f. Seems like with newer bash you can use PS0 instead of that project, which probably would do the same without problems you see.

  • When I try to reproduce using Terminal.app instead of iTerm2.app (on mac), I am unable to reproduce the unexpected output. Excellent sleuthing - I have added this and other supporting information to the bottom of my post for further clarification of what i was seeing.
    – WEBjuju
    Commented Dec 26, 2017 at 21:03

Had the issue when migrating data from an old laptop to a new one. __bp_preexec_invoke_exec and some others are defined in and sourced from ~/.iterm2_shell_integration.bash file.

In my case, the definitions were outdated, hence the noise. Follow the instructions from the following link to download the latest version: https://iterm2.com/documentation-shell-integration.html

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .