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

Variable

Meaning

\d

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

\h

The computer's hostname without the domain name.

\H

The computer's hostname with the domain name.

\s

The shell's name.

\t

The time in 24-hour format.

\T

The time in 12-hour format.

\@

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

\u

The username of the current user.

\w

The current working directory.

\W

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