Environment Variable PS1

Source: Internet
Author: User

Take bash shell as an Example
In general, the default. bashrc should be:
~ /. Bashrc
Export PS1 = '\ U @ \ H: \ W \ $'
The above means: user @ host: Current directory $
Escape Sequence
If you use a colored prompt to increase personalization, you need to use escape sequences. The escape sequence is a control command that allows shell to execute a special step. Generally, escape sequences start with ESC (which is also the reason for its naming ). ^ [. This representation takes a little time to adapt, or you can use \ 033 to complete the same work (esc ascii code is expressed in decimal format as 27, equal to 033 in octal format)
Code :
PS1 = "\ [\ 033 [1; 32; 40 m [\ 033 [0; 32; 40m \ U @ \ H: \ 033 [1; 35; 40m \ W \ 033 [1; 32; 40 m] \ 033 [1; 31; 40m \ $ \ 033 [1; 32; 40 m \]"
The outermost "\ [\]" is used to enclose the character strings of the escape sequence and prevent the text of the escape sequence from occupying too much space in shell.
\ 033 declares the start of the escape sequence, and then [begins to define the color. The following 0 defines the default font width, followed by a number in the middle to define the character color. The last digit defines the character background color. The letter M is necessary for definition, and the character after the letter M is the character you want to change.
Optional colors: Red, green, yellow, blue, magenta, cyan, and white. Their corresponding color codes are: 30 (black), 31 (red), 32 (green), 33 (yellow), 34 (blue), 35 (Foreign red), 36 (blue), 37 (white ).
Set the background color using the same color method, but Replace the first digit "3" with "4", for example, 40, 41, 42, 43, 44, 45, 46, and 47.
For example, in my definition above: the final result is that all the characters before $ are expanded with a light green middle arc. The $ character is displayed in red. The subsequent input is highlighted in light green. In the arc, the user name @ host is displayed as dark green, and the path is displayed as foreign red.
Use code to explain:
PS1 = "\ [-------------> outermost arc
\ 033 [1; 32; 40 m [
----> Define the rightmost "["; 1: font width, which seems to be highlighted.
32: Character Color. 32 indicates green.
40: background color. 40 indicates black.
\ 033 [0; 32; 40m \ U @ \ h:
---------> Define the \ U @ \ H on the right: These character colors.
0: default font width.
32: Character Color. Green.
40: background color. Black.
\ 033 [1; 35; 40 m \ W
---------> Define \ W (path color) on the right ).
1: character width. Highlight.
35: Character Color. Yang Hong.
40: background color. Black.
\ 033 [1; 32; 40 m]
---------> Define] characters on the right. Use the same effect as the preceding [character.
\ 033 [1; 31; 40m \ $
---------> The $ character is defined as red. Escape characters, so \.
The colors are similar to those in the front. I believe everyone has discovered the rule.
\ 033 [1; 32; 40 m
----------> This defines the color that you want to enter in the command line.
\]"
-----------> The string ends the arc.
This is the detailed definition of the above example.
In fact, I didn't turn off the color escape sequence, so that I could change the color of the characters I entered. It's cool to watch the black and white screen all day !! If you do not want to change the input color, use \ 033 [0 m to close the escape sequence. \ 033 [0 m is the default color of shell. In the above example, add \ 033 [0 m before.
Is it simple enough?
Let's look at the shell under root:
Rootshowg
This is also good. It's from Nico Golde:
PS1 = "\ [\ 033 [0; 37; 44m \ U @ \ 033 [0; 32; 43m \ H: \ 033 [0; 33; 41m \ W $ \ 033 [0m \]"

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.