5

Using set -x causes my shell to print unrelated stuff. For example:

$ set -x
++ printf $'%157s\r'
$ echo 'hello'
+ echo hello
hello
++ printf $'%157s\r'

The lines starting with '++' are extra. How can I remove those extra lines?

2 Answers 2

4

The -x flag isn't strictly "verbose", it's:

The shell shall write to standard error a trace for each command after it expands the command and before it executes it.

++ means this line of trace is coming from the shell's own internal processing while it thinks about your prompt. It's probably something that happens in your PROMPT_COMMAND: in that case, if you run:

PROMPT_COMMAND=
set -x

then you shouldn't get any more extra output.

It's possible you have other configuration causing it as well — Bash has a lot of prompt setup — and in that case bash -norc should avoid it entirely.


That said, this is essentially intended behaviour: -x is really meant for debugging shell scripts, rather than use in an interactive shell. It really is meant to print out every command that it runs, and that's what it's doing here - there's an extra command that runs with every prompt printed.

1

The extra output may also be produced by functions called from your $PS1 variable. Try to set it to a minimal prompt: export PS1='\u@h:\w \$ '

You must log in to answer this question.

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