Changing the Prompt

A shell presents a prompt when it's ready to receive input. You can change this prompt by setting the PS1 variable. For instance, if you want a simple $ prompt with no other adornment, you could type the following command:

Note There's no need to use the export keyword to set the prompt, because this variable is used internally to the shell; export makes a variable available to programs launched from a shell.

Chances are you'll want to use assorted variables in defining your prompt. Table 4.4 summarizes some of these (check the bash man page for more). A backslash (\) identifies the following character as a variable. Most Linux distributions use [\[email protected]\h \W]\$, or something similar, as their default prompt. This string results in a prompt ending in a dollar sign for ordinary users, and a hash mark (#) replaces the dollar sign for root logins.

Table 4.4: Common Variables Used in Setting the Shell Prompt




The date in "weekday month day" format, such asFri Nov 18.


The computer's hostname without the domain name.


The computer's hostname with the domain name.


The shell's name.


The time in 24-hour format.


The time in 12-hour format.


The time in 12-hour format with AM/PM indication.


The username of the current user.


The current working directory.


The final directory of the current working directory.


A dollar sign for most users, but a hash mark foroot.

Team LIB

Team LIB

0 0

Post a comment