Skip to content

Bash prompts

Quite often hosting providers by default will give a really stripped down bash prompt that isn't very helpful. A good example of this is UKFast.

Below is a fairly standard bash prompt that can be used instead, to give a more helpful output. This will need to be put in your users ~/.bashrc file, and can also be set just for the session by just running the command in the terminal with a prefix of export.

PS1="\e[0;37m[\u@\h \W]\$ \e[m "

In the above, the number 37 refers to the colour of the prompt, here's a list of colours:

  • Red: 31
  • Yellow: 33
  • Green: 32
  • White: 37

so for a red version of the above prompt, you would use PS1="\e[0;31m[\u@\h \W]\$ \e[m "

You can also make interactive prompts like this one below:

SELECT="if [ \$? = 0 ]; then echo \"${SMILEY}\"; else echo \"${FROWNY}\"; fi"

PS1="${RESET}${RED}\u${NORMAL}@${YELLOW}\h${NORMAL} ${white}\w${NORMAL} \`${SELECT}\` ${YELLOW}>${NORMAL}"
The above prompt will show either a smiley or frowny face based on the outcome of your last entered command e.g. if it fails/errors will show :( and if it's successful it will show :)