Modifying a Prompt
Learn how to modify a prompt in a shell environment.
We'll cover the following...
The PS1
variable
PS1
is a primary prompt variable, The value of the PS1
variable lets us specify what our prompt should look like. We can put lots of information in our prompt, including our username, our current working directory, and much more.
Changing the prompt text
Let’s start by creating a prompt that’s nothing more than the dollar sign with space after it. We add this line to our~/.bashrc
file:
PS1='\$ '
The \$
sequence displays a dollar sign for regular users and a pound sign (#
) for root users. Using single quotes around the prompt value ensures that the value isn’t expanded into a literal dollar sign.
Let’s add the current working directory to the prompt. We add \w
, which shows the full path to the current directory unless the directory is in the home directory, in which case it displays ~
instead:
PS1='\w \$ '
To add ...