3

I noticed whenever I source a file, the color of user@hostname changes:

enter image description here

Why?

6

Because it loads the user setings specified in your /etc/bash.bashrc file. And the prompt settings may be different from your actual terminal context. For more details have a look at the other upvoted answers. :)

6

This is because /etc/bash.bashrc sets a new value for your prompt:

# set a fancy prompt (non-color, overwrite the one in /etc/profile)
# but only if not SUDOing and have SUDO_PS1 set; then assume smart user.
if ! [ -n "${SUDO_USER}" -a -n "${SUDO_PS1}" ]; then
  PS1='${debian_chroot:+($debian_chroot)}\u@\h:\w\$ '
fi
6

The appearance of the prompt (the user@host thing) is controlled by the variable PS1. Probably you have something like

PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '

in your ~/.bashrc file. The weird \[\033[00m\] etc. characters are used for colouring the prompt. \u is the username (h4ck3r), \h is the hostname (h4ck3rE780) and \w is the current working directory (~ which denotes your HOME directory).

When you source /etc/bash.bashrc then the variable PS1 gets set to some other value (without colours) and you get a different prompt. It's quite simple.

Try

PS1='user=\u, host=\h, directory=\w $'

in a terminal window and see the result. Sourcing /etc/bash.bashrc doesn't do anything different (besides the actual parameters).

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.