Simply explain the settings for the PS1 default prompt in the Linux system

Source: Internet
Author: User
Tags uppercase character

PS1 (is the number 1 instead of the letter L), there may be a small difference in the special notation within each version of Bash's PS1 variable, and you can bash the man first. The following are the meanings that the default special symbols in the FC4 environment represent:

\d: Represents a date, formatted as weekday month date, for example: "Mon Aug 1"

\h: The full host name. For example: My machine name is: Fc4.linux, then this name is Fc4.linux

\h: Only the first name of the host, as in the example above, is omitted for Fc4,.linux

\ t: Displays a time of 24-hour format, such as: HH:MM:SS

\ t: Display time in 12-hour format

\a: Display time is 24 hour format: hh:mm

\u: Current user's account name

Version information for \v:bash

\w: The full working directory name. Home directory will be replaced by ~

\w: Use basename to get the working directory name, so only the last directory will be listed

\#: The first few orders issued

\$: Prompt character, if root, the prompt is: #, the average user is: $

The default PS1 content is: ps1= ' [\u@\h \w]\$ ', so the default prompt is: [Root@linux ~]#.
To change the input at the shell prompt:
The code is as follows:

[root@web1177 ~]# ps1= ' [\u@\h \w\#]\$ ']
This will let you know that you are entering the first few commands.

Below we will discuss in the shell variable assignment, first look at the bird book variable assignment:
1. Variables and variable contents are connected by equal sign (=);
2. Both sides of the equal sign can not directly connect spaces;
3. Variable name can only be English letters and numbers, but the number can not be the beginning of characters;
4. If there are spaces in the assignment, you can use double quotes or single quotes to combine the variables, but it is important to note that special characters within double quotes can hold variable attributes, but special characters within single quotes are only generic characters;
5. The need to use a backslash (\) to the special symbols (such as Enter, $, \, spaces, ' etc.) into general symbols;
6. In a sequence of instructions, you also need to use the information provided by other instructions, using the reference character (' command '); (especially note that ' is the button on the left of the number key 1 above the keyboard, not the single quote! )
7. If the variable is amplified variable content, you need to double quotes and $ variable names such as: "$PATH":/home continue to accumulate content;
8. If the variable needs to be executed in another subroutine, export will be required to change the variable to an environment variable, such as export PATH
9. Usually uppercase character is the system preset variable, the variable can be set by the use of lowercase characters, easy to judge (in accordance with the user's interests and hobbies);
10. The method for canceling a variable is: unset variable name.
So in the PS1 setting, because there are spaces in the middle, we need to use a single double quote, no result with the command required, so no reference is required. And we chose single quotes to get PS1 to accept pure characters directly, not characters that have special meaning in the shell, or variables that start with $, so we use single quotes, so we can also use double quotes.

Contact Us

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

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.