0

i have the following code for my prompt in .bashrc in home dir:

PS1_TIME='\033[01;31m\]\t \033[01;32m\]'
PS1_USERNAME='\[\e[1;36m\]\u\e[1;37m\]@\e[1;32m\]\h\[\033[00m\]'
PS1_LOCATION='\[\033[01;34m\]\w\[\033[00m\]'

PS1=$PS1_TIME$PS1_USERNAME':'$PS1_LOCATION'\n\$ '
PS2='\[\033[01;36m\]>'

I have also the following configuration in /etc/bashrc

# are we an interactive shell?
if [ "$PS1" ]; then
  if [ -z "$PROMPT_COMMAND" ]; then
    case $TERM in
    xterm*|vte*)
      if [ -e /etc/sysconfig/bash-prompt-xterm ]; then
          PROMPT_COMMAND=/etc/sysconfig/bash-prompt-xterm
      elif [ "${VTE_VERSION:-0}" -ge 3405 ]; then
          PROMPT_COMMAND="__vte_prompt_command"
      else
          PROMPT_COMMAND='printf "1\033]0;%s@%s:%s\007" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
      fi
      ;;
    screen*)
      if [ -e /etc/sysconfig/bash-prompt-screen ]; then
          PROMPT_COMMAND=/etc/sysconfig/bash-prompt-screen
      else
          PROMPT_COMMAND='printf "2\033k%s@%s:%s\033\\" "${USER}" "${HOSTNAME%%.*}" "${PWD/#$HOME/~}"'
      fi
      ;;
    *)
      [ -e /etc/sysconfig/bash-prompt-default ] && PROMPT_COMMAND=/etc/sysconfig/bash-prompt-default
      ;;
    esac
  fi

The result is that my shell prompt is configured of two: prompt from /etc is merged with my home settings

[PS1 from ect][PS1 from home dir]:

How to change my local settings so my home dir will override the default ones?

I don't want to change the file in etc or do i have to?

  • unset PROMPT_COMMAND – Ipor Sircer Jul 31 '18 at 8:51
  • there are some differences between gnu_terminal and terminal behavior in OSs. generally .bashrc overwrite /etc/bashrc. anyway, I guessed source ~/.bashrc sould solve your problem. – Hossein Vatani Jul 31 '18 at 10:30
1

PS1 and PROMPT_COMMAND are two different variables with different purposes. And, as Bash manual states:

PROMPT_COMMAND

If set, the value is interpreted as a command to execute before the printing of each primary prompt ($PS1).

Note that PROMPT_COMMAND is not intended to be used as the prompt, but as a command to be executed before the actual prompt is printed.

To fix this, and if you don't want to edit your /etc/bashrc, you need to either unset or assign a null value to PROMPT_COMMAND in your local .bashrc:

unset PROMPT_COMMAND
# or
PROMPT_COMMAND=

Example in an interactive session (foobar$ is my initial prompt):

foobar$ printf 'PROMPT_COMMAND: [%s]\nPS1: [%s]\n' "$PROMPT_COMMAND" "$PS1"
PROMPT_COMMAND: [printf foo]
PS1: [bar$ ]
foobar$ 

Unsetting PROMPT_COMMAND:

foobar$ unset PROMPT_COMMAND
bar$ 

Assigning a null value to PROMPT_COMMAND:

foobar$ PROMPT_COMMAND=
bar$ 

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.