Онлайн-рабочие станции OnWorks Linux и Windows

Логотип

Бесплатный хостинг в Интернете для рабочих станций

<Предыдущая | Содержание: | Следующая>

Анатомия подсказки

Our default prompt looks something like this:



[я @ linuxbox ~] $

[я @ 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 с эхо команда:


[я @ linuxbox ~] $ echo $PS1

[\ u @ \ h \ W] \ $

[я @ linuxbox ~] $ echo $PS1

[\ u @ \ h \ W] \ $


изображение

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.


изображение

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 такое как

Анатомия подсказки


those we saw in Chapter 7. Here is a partial list of the characters that the колотить 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.


изображение

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


изображение

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


изображение

\H Full hostname.


изображение

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


изображение

\l Name of the current terminal device.


изображение

\n A newline character.


изображение

\ r Возврат каретки.


изображение

\s Name of the shell program.


изображение

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


изображение

\T Current time in 12 hour format.


изображение

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


изображение

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


изображение

\u username of the current user.


изображение

\v Version number of the shell.


изображение

\V Version and release numbers of the shell.


изображение

\w Name of the current working directory.


изображение

\W Last part of the current working directory name.


изображение

\! History number of the current command.


изображение

\# Number of commands entered during this shell session.


изображение

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

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


изображение

\[ 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


изображение


изображение

cursor or changing text colors.


изображение

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


изображение


Лучшие облачные вычисления для ОС в OnWorks: