echo $PS1
Here are some common escape codes used:
\d
\h
\u
\w
We create a new variable, then copy the PS1 variable to it
ps1_old="$PS1"
PS1=\u@\h:\w\$
This will make more sense after you have read the chapter, but to change your PS1 prompt using an alias contains no spaces outside of the quotes and requires alternating quotation marks:
alias prompt1="PS1='\u@\h:\w\$'"
You can even nest a command inside the prompt
alias prompt2="PS1='$(date) \u@\h:\w\$'"
Refer to Table 13-2 for color schemes and their associated escape codes.
For example, \033[0;30m is black
\033[0;30m
\033[0;34m is blue
\033[0;34m
Shortcut: instead of using \033 we can simply use \e
\033
\e
As an example, a simple prompt like:
PS1='\[\033[1;32m\][\u@\h \W]\$\[\033[0m\] '
is the same as
PS1='\[\e[1;32m\][\u@\h \W]\$\[\e[0m\] '
Can be broken down into these elements:
\[\e[1;32m] - an opening square bracket printed in green (1;32m) [\u@h \W] - username@hostname and the basename of the current working directory \$ - the prompt (a # if the UID is 0) \[e[0m\] - the text reset escape signalling the end of the colour sequence.