Article Title: how to set a user prompt in bash. Linux is a technology channel of the IT lab in China. Includes basic categories such as desktop applications, Linux system management, kernel research, embedded systems, and open source.
Bash has two user prompts. The first level is the prompt that you often see when bash is waiting for command input. The default first-level prompt is the character $ (# if it is a super user ). You can change your default prompt by changing the value of the bash PS1 variable. for example, PS1 = "Please enter a command" converts the bash shell prompt to the specified string.
The second-level prompt is displayed when bash expects to enter more information to complete the command. The default second-level prompt is>. If you want to change the second-level prompt, you can set the PS2 variable value:
PS2 = "I need more information"
In addition, you can use special characters to define your prompt. the list below lists the most commonly used special characters.
Prompt special character code
Character meaning
\! Displays the history Number of the command.
\ # Display the command number of the current command.
\ $ Indicates the $ operator as the prompt. if the user is root, the # operator is displayed.
\ Display the backslash.
\ D displays the current date.
\ H displays the host name.
\ N print the new line.
\ Nnn: displays the nnn octal value.
\ S displays the name of the currently running shell.
\ T displays the current time.
\ U displays the user name of the current user.
\ W displays the name of the current working directory.
\ W displays the path of the current working directory.
These special characters can be combined into many useful prompt solutions (or can be combined into a very strange solution), such as setting PS1:
PS1 = "\ t"
This causes the prompt to display the current time, as shown below (there will be no space after the prompt ):
02:16:15
The following settings:
PS1 = \ t
The prompt will look like the following:
T
This shows the importance of setting quotation marks. the following prompt string:
PS1 = "\ t \\"
The prompt will look like this:
02:16:30 \
In this case, there is a space behind the prompt, because there is a space in the quotation marks.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service