2

Background

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

Question

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

    preexec_functions+=(preexec);
    __bp_preexec_interactive_mode="on"
__bp_preexec_invoke_exec ()
    if [[ -z "$__bp_preexec_interactive_mode" ]]; then
            __bp_preexec_interactive_mode="";
        __bp_preexec_interactive_mode="";
    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";
            preexec_ret_value="$?";
    __bp_set_ret_value "$preexec_ret_value" "$__bp_last_argument_prev_command"
    if [[ -z "${iterm2_ran_preexec:-}" ]]; then
        __iterm2_preexec "";
    iterm2_ran_preexec="";
__iterm2_preexec ()
    iterm2_ran_preexec="yes";

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 Dec 26 '17 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 Dec 26 '17 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 Dec 26 '17 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 Dec 26 '17 at 17:45
5

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 Dec 26 '17 at 21:03

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.