Bash's prompt
In April 2005, it reprinted: Searched by Google
BASH has two levels of prompts. The first level prompt is the situation that the BASH that is often seen is waiting for the command to enter. The default value of the first level prompt is a symbol. If the user does not like this symbol, or willing to define the prompt himself, simply modify the value of the PS1 variable. For example, it will be changed to:
PS1 = "Enter a commnd:"
The second level prompt is displayed when the BASH needs to be used to enter more information for execution of a command. The second level prompt defaults to>. If you need to define your prompt, you only need to change the value of the PS2 variable. For example, it will be changed to:
PS2 = "more information:"
The above two examples are the case where the setting prompt is a static string. In fact, users can also use some special characters that have been defined in advance. These special characters will enable the prompt that contain information such as the current time. Table 10-4 lists some of the most common special characters and its meaning.
Table 10-4 BASH prompt often use special characters
Special Character Description /! Show history number / # Display SHELL activation, the history number / $ display of the current command displays a $ symbol, if the current user is root, display # symbol // display a backslash / / D display The current date / h displays the computer host name / n printing the shell, which will cause the prompt cross-row / s to display the name / T of the running shell display Current time / u Display the current user's username / W display Current Work Catalog Benchmark Name / W Displays the current work directory
These special characters can be combined to provide users with some prompts to provide very useful information. Let's take a few practical examples:
PS1 = "/ t"
The prompt will be made as follows:
02:16:15
PS1 = / T
The prompt will be made as follows:
t
If ps1 = "/ t //"
The prompt will be made as follows:
02: 16: 30 /
This example is obtained using two special characters.