Introduction to the PS1 variable of SHELL in Linux

Source: Internet
Author: User
In Linux environment variables, PS1 is an important environment variable: PS (PromptSign): refers to a command prompt. for example, on a Fedora12 terminal: [liutao @ liutao ~] $. When setting the PS1 environment variable, we need to use some preset special symbols to set PS1. The following is laruence... in Linux environment variables, PS1 is an important environment variable: PS (Prompt Sign): refers to a command Prompt. for example, on a Ora 12 terminal: [liutao @ liutao ~] $. When setting the PS1 environment variable, we need to use some preset special characters to set PS1. Below is a special variable about BASH in laruence. O \ d: represents the Date, in the format of Weekday Month Date, for example, "Mon Aug 1" o \ H: complete host name. For example, if the host name is linux.dmtsai.tw, the host name is linux.dmtsai.tw www.2cto.com o \ h: only the first name of the host name is used. As mentioned above, it is just linux, and .dmtsai.tw is omitted. O \ t: display time, in the 24-hour format, for example, HH: MM: SS o \ T: display time, 12-hour time format! O \ A: display time, in 24-hour format, HH: MM o \ u: current user account name; o \ v: BASH version information; o \ w: complete working directory name. In the home directory ~ Replace; o \ W: get the working directory name using basename, so only the last directory name is listed. O \ #: commands issued. O \ $: the prompt character. if it is root, the prompt character is #; otherwise, it is $. Under Fedora 12, the content of PS1 is:

The example in the Bird's brother book is: [root @ linux/home/dmtsai 16:50 #12] # PS1 = '[\ u @ \ h \ w \ A ###] \ $' implementation on Fedora 12:

In the above example, we can see that PS1 uses single quotation marks (') when assigning values. next we will discuss how to assign values to SHELL variables. let's first look at the variable assignment in laruence's book: 1. the variable and the variable content are connected by equal signs (=); 2. the equal sign cannot be directly followed by a space character; 3. the variable name can only contain English letters and numbers, but cannot start with a number. 4. if there is a space character in the value assignment, you can use double quotation marks or single quotation marks to combine the variable content, but pay special attention to it. special characters in double quotation marks can retain the variable property, however, special characters in single quotes are only common characters; 5. if necessary, special characters (such as Enter, $, \, space character, and ') must be converted into general characters by backslash (\). 6. you can use the reference character ('command') in the information provided by other commands, that is the button on the left of the number key 1 on the top of the keyboard, not a single quotation mark !) Www.2cto.com 7. if the variable is the content of the expanded variable, double quotation marks and $ variable names such as "$ PATH":/home must be used to accumulate the content; 8. if the variable needs to be executed in other subprograms, use export to convert the variable into an environment variable, such as export PATH 9. generally, upper-case characters are system preset variables. you can use lower-case characters to set variables for easy judgment (purely based on user interests and hobbies). 10. the method for canceling a variable is: unset variable name. In the settings of PS1, because there are spaces in the middle, we need to use a single double quotation mark, there is no result with the command to be used, so reference is not required. We chose single quotes to allow PS1 to accept pure characters directly, instead of special characters in SHELL or variables starting with $, so we can use single quotes, double quotation marks can also be used. Author: wendaotao
Related Article

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.