Bash: Customization of prompt

How to display a custom string at the bash prompt?

Use the PS1 shell variable to display a custom string like the following:

> PS1="\u@\h \w> "

Bash uses the prompt string, PS1 shell variable to determine how to display the prompt. The prompt string for the example above looks like follows:

s265s0**@a00 /home/directory> type some command here

\u displays the username, \h displays the hostname and \w displays the current directory. If you log in your home computer, the hostname will be different. There is also another way to display the current directory by using \${pwd} as follows:

> PS1="\n[\u@\h \${pwd}"

[alan's comment: ]

In the above example, we are giving an indirect reference to a shell variable, by putting a \ before the $. This means wait until evaluation time before getting the value of the variable. This is how the prompt changes when you change directories. If we left out the \, then the prompt would have the value of the current working directory and would remain the same after changing directories.

Elaborated from Alan's Lab Notes. See a list of other special characters that you can use in PS1 at