One can update terminal titles using the following syntax:

echo -ne "\033]0;TITLE\a"

where \a can also be \007. For dynamically updating the window title (on process start), I put the following in my .bashrc (inspired by this answer, simplified):

    echo -ne "\033]0; ${BASH_COMMAND} \a"

Works fine. However, now when I want to print colored output:

echo -e "\033[0;33m SOME YELLOW TEXT"

, the output contains the command and results in ascii salad: see screenshot below.

enter image description here

  1. Why?
  2. How do I fix this?

1 Answer 1


That's two questions:

  • why?

    escape sequences don't nest. The title-sequence starts with \033]0; and ends with \a or any other control sequence.

  • how do you fix this?

    You could sanitize the bash command by assigning that to a variable and using shell parameter substitution to remove escape characters (and \a ASCII BEL). Just to make it look nice, you should also remove the square brackets (either [ or ]) after an escape character, as well as the numeric parameters that may follow.

Someone may provide an example using BASH_REMATCH (set as a side-effect of regex-matching) and use that as the word in a ${parameter##word} substitution...

  • I ended up with something like newTerminalTitle="${BASH_COMMAND//\\/\\\\}". the nesting totally makes sense, I havent thought of it.
    – phil294
    Jun 3, 2017 at 14:14

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.