O'Reilly logo

Linux in a Nutshell, 6th Edition by Robert Love, Stephen Figgins, Ellen Siever, Arnold Robbins

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Special Prompt Strings

Bash processes the values of the built-in shell variables PS1, PS2, and PS4 for the following special escape sequences:

Escape sequence

Description

\a

An ASCII BEL character (octal 07).

\A

The current time in 24-hour HH:MM format.

\d

The date in “weekday month day” format.

\D{ format}

The date as specified by the strftime(3) format format. The braces are required.

\e

An ASCII Escape character (octal 033).

\h

The hostname, up to the first period.

\H

The full hostname.

\j

The current number of jobs.

\l

The basename of the shell’s terminal device.

\n

A newline character.

\r

A carriage-return character.

\s

The name of the shell (basename of $0).

\t

The current time in 24-hour HH:MM:SS format.

\T

The current time in 12-hour HH:MM:SS format.

\u

The current user’s username.

\v

The version of Bash.

\V

The release (version plus patch level) of Bash.

\w

The current directory, with $HOME abbreviated as ~.

\W

The basename of the current directory, with $HOME abbreviated as ~.

\!

The history number of this command.

\#

The command number of this command.

\$

If the effective UID is 0, a # ; otherwise a $.

\@

The current time in 12-hour a.m./p.m. format.

\ nnn

The character represented by octal value nnn.

\\

A literal backslash.

\[

Start a sequence of nonprinting characters, such as for highlighting or changing colors on a terminal.

\]

End a sequence of nonprinting characters.

In Bash, the escape sequences are processed first. After that, variable, command, and arithmetic substitutions are performed if the promptvars shell option ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required