Enable bash -x

when I included bash -x in my linux console for every command I entered, I get this output.

printf "\033]0;% s@ %s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"

It is very annoying how I can disable it.

Thank you in advance

+4
source share
4 answers

The question was not why, but how to fix it. At the bash prompt, enter:

 unset PROMPT_COMMAND; PS1='\w> ' 

Now why. the command in PROMPT_COMMAND is evaluated after each bash command (it sets PS1 ), you usually do not see this activity. But with -x you can.

+3
source

This command prints an escape sequence to change the name of the terminal emulator. Therefore, I think it is configured in .bashrc or .bash_profile when TERM matches xterm* . Take a look there and comment on the code.

The command prints because bash -x displays each command, even if it is part of the print of $PS1 . This is why you probably don't want to use set -x in an interactive shell, but you probably should put your code in a script and add set -x at the beginning and set +x at the end (optional if you don't source it).

+4
source

This seems to be your $PROMPT_COMMAND variable in action. You can use $PS1 instead.

See http://www.gnu.org/software/bash/manual/bashref.html#index-PPID

0
source

You can use set -x to enable debugging and set +x to disable it.

If you have the debugging option enabled, BASH will print the value of $P4 for each line. By default, it is just + followed by a space. Try setting PS4='+ ' .

If this does not work, you have a Kornshell user who used $PROMPT_COMMAND to set the prompt. Usually, a hint displays useful information such as a username and directory. In BASH, you can do this using various escape sequences. For instance:

 PS1="\ u@ \h:\w$ " 

It will replace \u with the username, \h with the short host name and \w current directory based on the $HOME directory, if the user is in $HOME/bin , a prompt will appear

 david@foo-sys :~/bin$ 

If the user is in /usr/bin , the prompt will be

 david!@foo-sys :/usr/bin$ 

With Kornshell, you cannot use these escape sequences. Instead, you either call the cd or have a cd function that sets up the request. Or you use the syntax $(..) . I am using Kornshell and my hint looks like this:

 PS1=$(print -n "`logname`@`hostname`:";if [[ "${PWD#$HOME}" != "$PWD" ]] then; print -n "~${PWD#$HOME}"; else; print -n "$PWD";fi;print "\n$ ") 

Nastya, right? In BASH, I could do this:

 PS1="\ u@ \h:\w\n$ " 

In any case, it’s usual for Kornshell users to set the $COMMAND_PROMPT variable instead of using escape sequences when they use BASH because they know how to do it. And when you do this, you will see that the prompt command is printed every time. For example, I could set the BASH prompt as follows:

 PROMPT_COMMAND="print -n "`logname`@`hostname`:";if [[ "${PWD#$HOME}" != "$PWD" ]] then; print -n "~${PWD#$HOME}"; else; print -n "$PWD";fi;print "\n$ " 

and when I have set -x installed, I will see what prints every time.

What you need to do is go into $HOME/.bash_profile or, if $HOME/.profile does not exist, and get rid of the line where PROMPT_COMMAND set. Instead, change it to:

 PS1="\e]0\ u@ \h:\w\a$ " 

This is more or less the same invitation. If you do not want to change your .profile or .bash_profile , just do this:

 $ unset PROMPT_COMMAND $ PS="\e]0\ u@ \h:\w\a$ " 

Another possibility: you may not see that the tooltip is set to $HOME/.bash_profile , $HOME/.profile or even $HOME/.bashrc . In this case, you have a system administrator who has a Kornshell user, and they set the prompt in the /etc/profile file. You will have to override the invitation setting in your $HOME/.bash_profile file yourself by adding the two lines above to the end of the file.

0
source

All Articles