Skip to content
Search

Prompt Statement

lastmod 2022-02-22created 2020-10-094 edits

PS is short for PROMPT STATEMENT.

Variables

PS1
Current shell status information.
PS2
Identifies multi-line commands, such as when using for or select statements or breaking a line with an escape.
PS3
The text prompted in a bash select statement
PS4
Provides additional information when set -x is enabled for debugging
PROMPT_COMMAND
Command to run before PS1

Formatting

The formatters available in PS1 include the following.

Expression

Output

\t

Time in 24-hour format

\T

Time in 12-hour format

\@

Time in 12-hour format with AM/PM

\d

Current date

\s

Shell currently in use

\w

Absolute path of the current directory

\W

Current directory

\u

Username

\h

Hostname

\H

Domain name

\#

History of commands used

\!

Number in the history of commands used

\$

The # character if the current user is root, the $ character for a regular user

\n

Newline

\r

Carriage return

\v

Shell version

\V

Detailed shell version

Online tools

.bashrc generator
create your .bashrc PS1 with a drag and drop interface
http://bashrcgenerator.com/
  • Build a .bashrc/PS1 terminal prompt with drag and drop
    • Generated as an export statement, with a preview
  • hostname, username, shell name, terminal, directory, directory (basename), exit status
  • Various time / date formats
  • Color can be chosen for each item (double-click)
bash PS1
https://dom111.github.io/bash-ps1
Paste in your existing PS1 string to help understand what each of the blocks does.
Add the items you want displayed and style them, with a live preview of how it'll (hopefully) look in your terminal emulator!
There is also a tool that analyzes your PS1 when you paste it in and lets you fine-tune it.

See also

Favorite site

author Zer0 sitemap