Special Prompt Strings

The ASCII BEL character, which is octal 007.
An ASCII Escape character, which is octal 033.
The hostname, up to the first period.
The full hostname.
A newline character, which is octal 012.
A carriage return character, which is octal 015.
The current time in 24-hour HH:MM:SS format.
The current time in 12-hour HH:MM:SS format.
The current user’s username.
The character represented by the octal value nnn.
Start a sequence of nonprinting characters, such as for highlighting or changing colour on a terminal.
End a sequence of nonprinting characters.


# configure the Bash startup file ~/.bashrc
# - set prompt string: [time]user@host:path$
# - set prompt colour: blue if last return value is 0; red otherwise

PS1="\`if (( \$? == 0 )); then echo '\[\e[0;34m\][\t]\u@\h:\w\\$'
  else echo '\[\e[0;31m\][\t]\u@\h:\w\$'; fi\` \[\e[m\]"