Why does 'set -x' cause the terminal to dump garbage This problem is quite annoying and I cannot search Google for 'set -x' because the minus sign has another terminology there.

In my MacBookPro, when I use 'set -x' to debug bash commands, I'm getting the following each time I press enter. Any idea how to stop this ugly dump? because of this, for each command I run, I need to scroll back two pages to find the actual command I was running.

++ update_terminal_cwd
++ local url_path=
++ local i ch hexch LC_CTYPE=C LC_ALL=
++ (( i = 0 ))
++ (( i &lt; 24 ))
++ ch=/
++ [[ / =~ [/._~A-Za-z0-9-] ]]
++ url_path+=/
++ (( ++i ))
++ (( i &lt; 24 ))
++ ch=U
++ [[ U =~ [/._~A-Za-z0-9-] ]]
++ url_path+=U
++ (( ++i ))
++ (( i &lt; 24 ))
++ ch=s
++ [[ s =~ [/._~A-Za-z0-9-] ]]
++ url_path+=s
++ (( ++i ))
++ (( i &lt; 24 ))
++ ch=e
++ [[ e =~ [/._~A-Za-z0-9-] ]]
++ url_path+=e
++ (( ++i ))
++ (( i &lt; 24 ))
++ ch=r
++ [[ r =~ [/._~A-Za-z0-9-] ]]
++ url_path+=r
++ (( ++i ))
++ (( i &lt; 24 ))
++ ch=s
++ [[ s =~ [/._~A-Za-z0-9-] ]]
++ url_path+=s
++ (( ++i ))
++ (( i &lt; 24 ))
++ ch=/
++ [[ / =~ [/._~A-Za-z0-9-] ]]
++ url_path+=/
++ (( ++i ))
++ (( i &lt; 24 ))
++ ch=i
++ [[ i =~ [/._~A-Za-z0-9-] ]]
++ url_path+=i
++ (( ++i ))
++ (( i &lt; 24 ))
++ ch=s
++ [[ s =~ [/._~A-Za-z0-9-] ]]
++ url_path+=s
++ (( ++i ))
++ (( i &lt; 24 ))
++ ch=h
++ [[ h =~ [/._~A-Za-z0-9-] ]]
++ url_path+=h
++ (( ++i ))
++ (( i &lt; 24 ))
++ ch=a
++ [[ a =~ [/._~A-Za-z0-9-] ]]
++ url_path+=a
++ (( ++i ))
++ (( i &lt; 24 ))
++ ch=h
++ [[ h =~ [/._~A-Za-z0-9-] ]]
++ url_path+=h
++ (( ++i ))
++ (( i &lt; 24 ))
++ ch=a
++ [[ a =~ [/._~A-Za-z0-9-] ]]
++ url_path+=a
++ (( ++i ))
++ (( i &lt; 24 ))
++ ch=k
++ [[ k =~ [/._~A-Za-z0-9-] ]]
++ url_path+=k
++ (( ++i ))
++ (( i &lt; 24 ))
++ ch=/
++ [[ / =~ [/._~A-Za-z0-9-] ]]
++ url_path+=/
++ (( ++i ))
++ (( i &lt; 24 ))
++ ch=D
++ [[ D =~ [/._~A-Za-z0-9-] ]]
++ url_path+=D
++ (( ++i ))
++ (( i &lt; 24 ))
++ ch=o
++ [[ o =~ [/._~A-Za-z0-9-] ]]
++ url_path+=o
++ (( ++i ))
++ (( i &lt; 24 ))
++ ch=w
++ [[ w =~ [/._~A-Za-z0-9-] ]]
++ url_path+=w
++ (( ++i ))
++ (( i &lt; 24 ))
++ ch=n
++ [[ n =~ [/._~A-Za-z0-9-] ]]
++ url_path+=n
++ (( ++i ))
++ (( i &lt; 24 ))
++ ch=l
++ [[ l =~ [/._~A-Za-z0-9-] ]]
++ url_path+=l
++ (( ++i ))
++ (( i &lt; 24 ))
++ ch=o
++ [[ o =~ [/._~A-Za-z0-9-] ]]
++ url_path+=o
++ (( ++i ))
++ (( i &lt; 24 ))
++ ch=a
++ [[ a =~ [/._~A-Za-z0-9-] ]]
++ url_path+=a
++ (( ++i ))
++ (( i &lt; 24 ))
++ ch=d
++ [[ d =~ [/._~A-Za-z0-9-] ]]
++ url_path+=d
++ (( ++i ))
++ (( i &lt; 24 ))
++ ch=s
++ [[ s =~ [/._~A-Za-z0-9-] ]]
++ url_path+=s
++ (( ++i ))
++ (( i &lt; 24 ))


Thank you!!
What you're seeing here is some fancy behind-the-scenes scriptery that Apple added in OS X 10.11 to set the Terminal window title based on the current working directory. Since set -x shows what commands are being executed by bash, it also winds up showing all this normally-behind-the-scenes stuff (in painful detail). It's fairly easy to disable it, though:

unset PROMPT_COMMAND


... and then you can debug in peace, but your window title bar won't update any more. If you're done debugging and want to re-enable title bar updates, just reset the variable:

PROMPT_COMMAND=update_terminal_cwd