SHARE
Facebook X Pinterest WhatsApp

The Various bash Prompts

Written By
thumbnail Juliet Kemp
Juliet Kemp
Sep 1, 2020
ServerWatch content and product recommendations are editorially independent. We may make money when you click on links to our partners. Learn More



It’s fairly likely that you already have a personalized setting for PS1, the default bash interaction prompt. But what about the others available: PS2, PS3, and PS4?

Tip of the Trade: Most likely, you already have a personalized setting for PS1, the default bash interaction prompt. Here’s what to do with PS2, PS3 and PS4.

PS1 is the default interaction prompt. To set it to give you

username@host:directory$

use

export PS1="u@h w$ "

in your ~/.bash_rc.
u is the current username, h the current host, and w the working directory. There’s a list of escape codes you can use
in the bash man page, or in the Bash Prompt HOWTO.

PS2 is the prompt you get when you extend a command over multiple lines by
putting at the end of a line and hitting return. By default it’s
just >, but you can make this a little more obvious with:

export PS2="more -> "

so it looks like:

juliet@glade:~ $ very-long-command-here 
more -> -with -lots -of -options

PS3 governs the prompt that shows up if you use the select
statement in a shell script. The default is #?, so if you do nothing to
change that, the select statement will print out the options and then just
leave that prompt. Alternatively, use this:

PS3="Choose an option: "
select i in yes maybe no
do 
	# code to handle reply
done

which will output:

1) yes
2) maybe
3) no
Choose an option: 

Far more readable for the user!

Finally, PS4 is the prompt shown when you set the debug mode on a shell
script using set -x at the top of the script. This echoes each line
of the script to STDOUT before executing it. The default prompt is
++. More usefully, you can set it to display the line number, with:

export PS4='$LINENO+ '

All of these can be made to be permanent changes by setting them in your
~/.bash_profile or ~/.bashrc file. (Note that this probably
makes little sense to do for PS3, which is better to set per-script.)

thumbnail Juliet Kemp

Juliet Kemp is a ServerWatch contributor.

Recommended for you...

What Is a Container? Understanding Containerization
What Is a Print Server? | How It Works and What It Does
Nisar Ahmad
Dec 8, 2023
6 Best Linux Virtualization Software for 2024
What Is a Network Policy Server (NPS)? | Essential Guide
ServerWatch Logo

ServerWatch is a top resource on servers. Explore the latest news, reviews and guides for server administrators now.

Property of TechnologyAdvice. © 2025 TechnologyAdvice. All Rights Reserved

Advertiser Disclosure: Some of the products that appear on this site are from companies from which TechnologyAdvice receives compensation. This compensation may impact how and where products appear on this site including, for example, the order in which they appear. TechnologyAdvice does not include all companies or all types of products available in the marketplace.