BASH Shell Change The Color of Shell Prompt on Linux or UNIX

Originally published at: https://www.cyberciti.biz/faq/bash-shell-change-the-color-of-my-shell-prompt-under-linux-or-unix/

How do I change the color of my shell prompt under Linux or Unix operating systems?

    ## Black       0;30     Dark Gray     1;30
    ## Blue        0;34     Light Blue    1;34
    ## Green       0;32     Light Green   1;32
    ## Cyan        0;36     Light Cyan    1;36
    ## Red         0;31     Light Red     1;31
    ## Purple      0;35     Light Purple  1;35
    ## Brown       0;33     Yellow        1;33
    ## Light Gray  0;37     White         1;37

My prompt:

PS1="[\[\e[1;34m\]$WINDOW\[\e[0m\]:\[\e[1;$UCOL\]\$(sens)\[\e[0m\]$SEP\u@\[\e[1;$ENV\]\h.$ENAME\[\e[0m\]:\[\e[1;31m\]\$(get_branch)\[\e[0m\] \w]\\$ ";

^ thats mine with some data pumped in via functions, but basically surround text with:

\[\e[1;34m\] XXX \[\e[0m\] <- light blue XXX

the start and end parts begin colour and end colour

1 Like

I am still facing line wrapping issue. My PS1 is as below. How can i change it to correct one

export PS1="\e[1;34m[\u@\h \W]$\[\e[0m\] "

If i use as given by Kevin above it still wraps the first line and then it works well but as i said it still wraps the first line and then it works fine.

Can some one please check

Welcome @pratkul007

Try the following:

export PS1="\e[1;34m[\u@\h \W]\$ \e[m "

Hi Vivek,

Thanks for your reply. but problem still exists.

if i copy paste below line first time in putty its ok, if i paste it second time it wraps the output, if i paste it third time it paste it one after the other (.i.e after the end of first line) but in that case it starts after one line below command prompt.

the line i am using: -
mirrorlist = http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=AppStream&infra=$infra

like this

output after pasting it 3-4 times… (see below pasted the command after the command prompt but after paste it for 3-4 times it showing as it started below the command prompt)

[prat@system4 ~]$
://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=AppStream&infra=$inframirrorlist = http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=AppStream&infra=$inframirrorlist = http://mirrorlist.centos.org/?release=$releasever&arch=$basearch&repo=AppStream&infra=$infra

Wrapping takes place as screen is small and texts/urls are bigger. Try maximising Putty window. Also state your Linux and bash shell version. Typically older version of distro and bash version many not work with newer fancy stuff.

cat /etc/os-release
bash --version