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
fororselectstatements or breaking a line with an escape.
-
PS3 - The text prompted in a bash
selectstatement
-
PS4 - Provides additional information when
set -xis enabled for debugging
-
PROMPT_COMMAND - Command to run before
PS1
Formatting
The formatters available in PS1 include the following.
| Expression | Output |
| | Time in 24-hour format |
| | Time in 12-hour format |
| | Time in 12-hour format with AM/PM |
| | Current date |
| | Shell currently in use |
| | Absolute path of the current directory |
| | Current directory |
| | Username |
| | Hostname |
| | 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 |
| | Newline |
| | Carriage return |
| | Shell version |
| | Detailed shell version |
Online tools
- .bashrc generator
- create your .bashrc PS1 with a drag and drop interface
- http://bashrcgenerator.com/
- Build a
.bashrc/PS1terminal 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)
- Build a
- 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.