Customizing Your Prompt
The default Bash interactive prompt is a dollar sign ($), although some distributions use a different symbol. Most Linux distributions redefine the prompt to include additional information, such as your current login and computer, which is useful when you're moving between accounts and computers.
If a variable named PS1 (prompt string 1) is defined, Bash will use the value of this variable for your main prompt. If you include variable names in the string, Bash will substitute the value of the variables into your prompt.
$ declare -x PS1="Bash $ " Bash $ pwd /home/kburtch/archive Bash $
The following declares a three-line prompt with a blank line, the current directory, the old current directory, login name, computer name, and a bold $.
$ declare -x PS1=" \$PWD (\$OLDPWD) \$LOGNAME@'uname -n'\['tput bold'\] \$ \['tput rmso'\]" /home/kburtch/archive (/home/kburtch/work) kburtch@linux_box $
The \[ and \] should surround the display formatting characters returned by tput. Otherwise, Bash assumes that all the prompt characters are printable and will not wrap long input lines properly.
Bash has a PS2 (prompt string 2) variable, which is the prompt for incomplete command lines such as when you use a multiline quotation. By default, this prompt is a greater-than sign (>).
Bash recognizes the following escape sequences in a prompt.
\aA beep (the ASCII bell character)
\A24 time in HH:MM format
\dThe date in "weekday-month-date" format
\D{s}Runs the C statftime function with format string s
\eThe ASCII escape character
\hThe hostname
\HThe complete hostname, including the domain
\jThe number of jobs in the job table
\lThe tty device
\nA new line
\rA carriage return
\sThe name of the shell
\tThe 24 hour time
\TThe 12 hour time
\@The time in AM/PM format
\uThe username
\vThe Bash version
\VThe Bash release
\wThe current working directory
\WThe basename of the current working directory
\!The position of the command in the history list
\#The sequential command number for the session
\$Default prompt (# for the superuser, otherwise $)
\nnnASCII character in octal format
\\A backslash
\[Begins a sequence of nonprintable characters
\]Ends a sequence of nonprintable characters
Variables are discussed more in Chapter 5. You can disable variable substitution by turning off the promptvars shell option.