Q:

How to customize the command prompt?

I'm willing to change my command prompt to be something like
user$

where user is not root and
root#

When the current user is root. I've searched for that and found that this is achieved through the \$ special character and now I have something like this in my ~/.bashrc
PS1="\u\$ "

Unfortunately, the \$ is not displayed as a # when the current user is root. For example, after executing
user$ sudo bash

I get my command prompt
root$

Instead of
root#

Am I missing something?

A:

Add the following line in your ~/.bashrc
if [ "$(whoami)" = "root" ]; then PS1="\u# "; else PS1="\u\$ "; fi

when you open a new terminal you will get,
user$
user$ sudo bash
root#

Note: It will work only with sudo bash. As sudo -i or sudo su will check /root/.bashrc instead of user's .bashrc. To get the same behavior copy the same in /root/.bashrc also.
Alternate Better Way:
The same thing can be achieved by setting PS1 as
PS1="\u\\$ "          

in user's as well as root's .bashrc

