Search⌘ K

The Prompt

Explore how to set and control the Bash prompt by understanding PS1, PS2, PS3, and PS4 variables. Learn to customize your prompt with escape sequences for useful details and automate commands with PROMPT_COMMAND, enhancing your command line environment effectively.

Now that you’ve learned about escapes and special characters you are in a position to understand how the bash prompt can be set up and controlled.

How Important is this Lesson?

This lesson is not essential, but most people find it interesting and maybe fun to learn about.

The PS1 Variable

Type this:

Shell
bash
PS1='My super prompt>>>> '
ls
exit
Terminal 1
Terminal
Loading...

As you’ll remember, there are some shell variables that are set within bash that are used for various purposes. One of these is PS1, which is the prompt you see after each command is completed.

The PS2 Variable

Shell
bash
PS2='I am in the middle of something!>>> '
cat > /dev/null << END
some text
END
exit

The PS2 variable is the ‘other’ prompt that the shell uses to indicate that you are being prompted for input to a program that is running. By default, this is set to >, which is why you see that as the prompt when you normally type the cat command above in.

PS3

PS3 is used by the select looping structure. We don’t cover that in this book as I’ve barely ever seen it used.

PS4

...