IT 1100 Introduction to Operating Systems

Chapter 13 Customizing the Prompt


Displaying the Prompt

Here are some common escape codes used:


Backing up the current prompt

We create a new variable, then copy the PS1 variable to it

ps1_old="$PS1"


Creating a new prompt

This will make more sense after you have read the chapter, but to change your PS1 prompt using an alias contains no spaces outside of the quotes and requires alternating quotation marks:

You can even nest a command inside the prompt


Adding Color to Prompts

Refer to Table 13-2 for color schemes and their associated escape codes.

For example, \033[0;30m is black

\033[0;34m is blue

Shortcut: instead of using \033 we can simply use \e


Adding Color to Prompts

As an example, a simple prompt like:

PS1='\[\033[1;32m\][\u@\h \W]\$\[\033[0m\] '

is the same as

PS1='\[\e[1;32m\][\u@\h \W]\$\[\e[0m\] '

Can be broken down into these elements:

\[\e[1;32m] - an opening square bracket printed in green (1;32m)

[\u@h \W] - username@hostname and the basename of the current working directory

\$ - the prompt (a # if the UID is 0)

\[e[0m\] - the text reset escape signalling the end of the colour sequence.

Last Updated 03/27/2018