Centos 7 "set -x" causes a lot of stuff to appear in my terminal.

phoffric used Ask the Experts™
I just installed Centos 7, and I get too much stuff being output when I use set -x. Weird, huh?
$ set -x
++ __vte_prompt_command
+++ sed 's/^ *[0-9]\+ *//'
+++ history 1
++ local 'command=set -x'
++ command='set -x'
++ local 'pwd=~'
++ '[' /home/admin/Tst '!=' /home/admin ']'
++ pwd='~/Tst'
+++ __vte_osc7
++++ __vte_urlencode /home/admin/Tst
++++ LC_ALL=C
++++ str=/home/admin/Tst
++++ '[' -n /home/admin/Tst ']'
++++ safe=/home/admin/Tst
++++ printf %s /home/admin/Tst
++++ str=
++++ '[' -n '' ']'
++++ '[' -n '' ']'

Open in new window

Furthermore, if I type any command, such as ls -l, I get the above stuff with some additional stuff which is possibly related to the specific command. To see the results of the command, I have to scroll up. So, please tell me how to get rid of this stuff and just in case this stuff can prove useful someday, how do I turn this stuff back on?

If I use a -x in a bash script or function in .bashrc, the stuff even spills out past the script.
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Nick UpsonPrincipal Operations Engineer
the command "set -x" causes the shell to echo all lines out before executing them, this is exactly as intended, to remove just do "set +x"
David FavorFractional CTO
Distinguished Expert 2018
Issuing a set -x produces a line-by-line dump of every shell operation, so setting this will create a massive amount of output.

The purpose of set -x is to produces copious output for debugging.

Once you issue set -x, this output will continue till you issued set +x to disable tracing/debugging.

Keep in mind .bashrc has no scope like programming languages or maybe global scope, if you prefer... so you must issue set +x to disable this output.

Suggestion: Mention what you're trying to accomplish by enabling tracing/debugging for additional help.
I know about set +x.
In the past, I have run bash scripts with the -x option, or IIRC, set -x within the script, and got just the command lines printed out without all the extra stuff.
Are you both saying that if I want to debug a bashrc function or a bash script, I must get all the extra stuff?
Acronis in Gartner 2019 MQ for datacenter backup

It is an honor to be featured in Gartner 2019 Magic Quadrant for Datacenter Backup and Recovery Solutions. Gartner’s MQ sets a high standard and earning a place on their grid is a great affirmation that Acronis is delivering on our mission to protect all data, apps, and systems.

Duncan RoeSoftware Developer
From https://www.experts-exchange.com/questions/29165190/#a42987761
And every time I hit the Enter or even ls -l, I get the above.
Well, it's not PS1 (thanks for posting yours, I tried it).
Try this: echo $PROMPT_COMMAND. If it's not empty, find out where it gets set and get rid of it. Places to look include /etc/profile, all the files in /etc/profile.d/, ~/.bashrc, ~/.profile, ~/.bash_profile and so on. Once you have gotten rid of it, reboot the VM to be really sure it's gone. Now try set -x again and see what other junk we have to get rid of.
Distinguished Expert 2017
Much depends when and where you use set -x

You may have used set -x, but forgot to turn it off.

I.e. Surround the items of interest with set -x and set +x after when you want the debug features of interest to you.
Duncan RoeSoftware Developer
On second thoughts, simply unset PROMPT_COMMAND and see what effect that has when you set -x
David FavorFractional CTO
Distinguished Expert 2018
You said, "I know about set +x. In the past, I have run bash scripts with the -x option, or IIRC, set -x within the script, and got just the command lines printed out without all the extra stuff. Are you both saying that if I want to debug a bashrc function or a bash script, I must get all the extra stuff?"

Keep in mind...

.bashrc != script

1) When make a change at the .bashrc level, this change is global + remains in effect until reversed. Period. Forever.

This effects all scripts, not just one.

2) When you make a change at a script level, the exact same thing occurs. You've effected your script either globally or inside a function.

Independent of what options you set in your script, these options occur within the script's scope + have no effect on the global scope (all scripts).

So this effects only one script, not all scripts.
At work (RHEL 7.4), when I open my first window and type set -x, only two lines appeared - tolerable.
>> Try this: echo $PROMPT_COMMAND.
[user@localhost ~]$ echo $PROMPT_COMMAND

Open in new window

[root@localhost ~]# echo $PROMPT_COMMAND
printf "\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"
[root@localhost ~]# set -x
++ printf '\033]0;%s@%s:%s\007' root localhost '~'

Open in new window

>>  unset PROMPT_COMMAND  What does a prompt command have to do with the big mess in the OP?
This resulted in nice behavior. How did you know?
How should this  be changed in /etc/profile.d/vte.sh ?
case "$TERM" in
    [ -n "$BASH_VERSION" ] && PROMPT_COMMAND="__vte_prompt_command"
    [ -n "$ZSH_VERSION"  ] && precmd_functions+=(__vte_osc7)

Open in new window

The unset command seemed to do the job. Thank you much.
Duncan RoeSoftware Developer
rm /etc/profile.d/vte.sh
i rm vte.sh, and now I get after a restart, I get something new:
bash: a#: command not found...
bash: aliias: command not found...
Similar command is: 'alias'
bash: __vte_prompt_command: command not found...

Open in new window

I think I should have backed up that vte.sh as there were other things in it.
[user@localhost ~]$ set -x
++ __vte_prompt_command
++ local runcnf=1
++ local retval=127
++ [[ himxBH =~ i ]]
++ [[ ! -S /run/dbus/system_bus_socket ]]
++ [[ ! -x /usr/libexec/packagekitd ]]
++ [[ -n '' ]]
++ '[' 1 -eq 1 ']'
++ /usr/libexec/pk-command-not-found __vte_prompt_command
bash: __vte_prompt_command: command not found...
++ retval=127
++ return 127
[user@localhost ~]$ 

Open in new window

What do all these lines mean, and where do they come from?
David FavorFractional CTO
Distinguished Expert 2018
aliias is misspelled.

Use alias instead.

This may fix your problem.
thanks for pointing out the mispelling.

Now when I open a terminal or enter a cmd line, I get:
bash: __vte_prompt_command: command not found...

Open in new window

Turns out that I had saved the original vte file. So, I restored it, and am back to where I began in the OP.

I took a quick look at  /etc/profile.d/vte.sh, and now I see that all the stuff in the OP is from that file. Removing the file caused the above error even without the set -x, so what do you recommend?
Distinguished Expert 2017
Since running "unset PROMPT_COMMAND" help

you could within .bashrc
at the end of the file, add

and be done with it.
Thanks for helping me get rid of this stuff.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial