OnWorks Linux and Windows Online WorkStations

Logo

Free Hosting Online for WorkStations

< Previous | Contents | Next >

Anatomy Of A Prompt

Our default prompt looks something like this:



[me@linuxbox ~]$

[me@linuxbox ~]$


Notice that it contains our username, our hostname and our current working directory, but how did it get that way? Very simply, it turns out. The prompt is defined by an environ- ment variable named PS1 (short for “prompt string one”). We can view the contents of PS1 with the echo command:


[me@linuxbox ~]$ echo $PS1

[\u@\h \W]\$

[me@linuxbox ~]$ echo $PS1

[\u@\h \W]\$


image

Note: Don't worry if your results are not exactly the same as the example above. Every Linux distribution defines the prompt string a little differently, some quite exotically.


image

From the results, we can see that PS1 contains a few of the characters we see in our prompt such as the brackets, the at-sign, and the dollar sign, but the rest are a mystery. The astute among us will recognize these as backslash-escaped special characters like

Anatomy Of A Prompt


those we saw in Chapter 7. Here is a partial list of the characters that the bash treats spe- cially in the prompt string:


Table 13-1: Escape Codes Used In Shell Prompts


Sequence Value Displayed

Sequence Value Displayed

\a ASCII bell. This makes the computer beep when it is encountered.


image

\d Current date in day, month, date format. For example, “Mon May 26.”


image

\h Hostname of the local machine minus the trailing domain name.


image

\H Full hostname.


image

\j Number of jobs running in the current shell session.


image

\l Name of the current terminal device.


image

\n A newline character.


image

\r A carriage return.


image

\s Name of the shell program.


image

\t Current time in 24 hour hours:minutes:seconds format.


image

\T Current time in 12 hour format.


image

\@ Current time in 12 hour AM/PM format.


image

\A Current time in 24 hour hours:minutes format.


image

\u username of the current user.


image

\v Version number of the shell.


image

\V Version and release numbers of the shell.


image

\w Name of the current working directory.


image

\W Last part of the current working directory name.


image

\! History number of the current command.


image

\# Number of commands entered during this shell session.


image

\$ This displays a “$” character unless we have superuser privileges.

In that case, it displays a “#” instead.


image

\[ Signals the start of a series of one or more non-printing characters.

This is used to embed non-printing control characters which manipulate the terminal emulator in some way, such as moving the


image


image

cursor or changing text colors.


image

\] Signals the end of a non-printing character sequence.


image


Top OS Cloud Computing at OnWorks: