Bash Prompt Colors Ubuntu

bashbashrcprofile

I am attempting to use a simple shell script on a base Ubuntu 12.04 server install to set prompt colors for users system wide.

I would like to have Puppet place the file color.sh in /etc/profile.d/ — with permission 744

but the file isn't being sourced by users at all. ~/.bashrc appears to override this.

    if [[ ${EUID} == 0 ]] ; then
        PS1="\\[\\033[01;31m\\]\\h\\[\\033[01;34m\\] \\W \\$\\[\\033[00m\\] "
else
        PS1="\\[\\033[01;32m\\]\\u@\\h\\[\\033[01;34m\\] \\w \\$\\[\\033[00m\\] "
fi

I would prefer not to manipulate ~/.bashrc files with Puppet, but instead have this work globally with profile.d script.

Best Answer

The default Ubuntu ~/.bashrc will overwrite any earlier values of PS1 which is what you're seeing. You could make PS1 read only

declare -r PS1=...

but this will cause the default ~/.bashrc to emit

-bash: PS1: readonly variable

which may not be desirable. You can edit /etc/skel/.bashrc to remove the lines that set PS1 so that new users will not get init scripts that by default try and overwrite your global PS1 definition. That won't stop them from adding their own PS1 definitions but the error message above would clue them in.