I'm abusing traps to do a little window titling magic. When the user presses enter on a command line, the window title is updated to include the command line they issued:

Code:
function dont_trap {
  trap DEBUG
}

function do_trap {
  trap 'echo -en "\e]0;$TRIM> $BASH_COMMAND\007"; dont_trap' DEBUG
}

export PROMPT_COMMAND='export TRIM=`~/bin/trim.pl`; do_trap'
export PS1="\[\e]0;\%TRIM\a\]\$TRIM> "
Ignore $TRIM and trim.pl for now. All they do is pretty-up my current working directory and prepend the machine name.

The problem is that the 'export TRIM=`~/bin/trim.pl`' bit is making it into the window title. Depending upon the system it may be there for a half second or more. On cygwin, for example, I might see 'sleep 5' up there for 5 seconds, but then I see 'export......' for about a half second.

My understanding of the order of operation here is that when my bash window starts, the first prompt will call do_trap, causing the next press of return to fire the DEBUG trap, which changes the window title, but should then deactivate the trap, allowing the 'export TRIM' bit to execute silently. (goto 10)

I'm guessing that the do_trap is executing in the context of my command prompt, but that the trap (the echo -en.....; dont_trap) bit is executing in a subshell, and therefore the dont_trap only affects the subshell and not the main shell. This led me to attempt to do the 'dont_trap' call in the PROMPT_COMMAND line before the export, but this produces the same result, oddly enough.

So anyway, I'm curious as to whether there is a solution to this or if I'm chasing a pointless aesthetic bug.

thanks....