Trying to customize shell prompt on a Ubuntu 18 LTS server over SSH.

On the server, the .profile sources .bashrc correctly, and .bashrc has force_color_prompt=yes uncommented. The prompt is not colored.

Tried setting it manually. It does not export:

user@ubuntu ~ $ export PS1="[ ${debian_chroot:+($debian_chroot)}\u is awesome: \w ]\\$ "
user@ubuntu ~ $ echo $PS1
\u@\h \w \$

But as root it works fine:

user@ubuntu ~ $ sudo su
root@ubuntu:/home/user# export PS1="[ ${debian_chroot:+($debian_chroot)}\u is awesome: \w ]\\$ "
[ root is awesome: /home/user ]#

What is going on?

  • Perhaps your ordinary user's login shell is not bash? – steeldriver Nov 28 '18 at 17:06
  • 1
    Please edit your question and show us the output of echo $PROMPT_COMMAND. Ideally, show us the entire contents of your ~/.bashrc. Also show us the output of ps -p $$ as your regular user. @steeldriver are there any shells that accept the foo=bar syntax for variables and don't support PS1? It's defined by POSIX for sh so I would be very surprised to find an sh-like shell that doesn't understand it. – terdon Nov 28 '18 at 17:55

Checked $PROMPT_COMMAND as advised by @terdon:

user@ubuntu ~ $ echo $PROMPT_COMMAND
__git_ps1 "\u@\h \w" "$(__drush_ps1 "[%s]") \\\$ "

Then looked harder at .bashrc and found:

# Include Drush prompt customizations.
if [ -f "/home/user/.drush/drush.prompt.sh" ] ; then
    source /home/user/.drush/drush.prompt.sh

Drush was setting its own $PROMPT_COMMAND, apparently instead of PS1. Not sure how PS1 gets overwritten by this, but it does. Commenting out Drush's superfluous customization makes the problem go away. Thanks to @terdon.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.