Customize personalized bash

Source: Internet
Author: User
Article Title: Custom 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.

Finally, we installed the Solaris 10 u8 on the Sun Fire V890 and got started with minicomputers.

Since Linux has been used for a long time, we like bash (bourne again shell) very much, but it is the default sh (bourne shell) for Solaris. After logging on, enter bash and you can easily switch to the bourne again shell, but why not let the machine do this mechanical action?

There are many ways to modify the default shell, one is to modify the/etc/passwd file:

1-bash-3.00 # cat/etc/passwd

2 root: x: 0: 0: Super-User: // bin/sh

3...

4...

5 user: x: 100: 1:/home/user:/bin/sh

Use VI to modify it.

Another method is to use the usermod command:

1-bash-3.00 # usermod-s/bin/bash root

2 UX: usermod: root is currently logged in, some changes may not take effect until next login.

3-bash-3.00 # usermod-s/bin/bash user

4 UX: usermod: user is currently logged in, some changes may not take effect until next login.

5-bash-3.00 # cat/etc/passwd

6 root: x: 0: 0: Super-User: // bin/bash

7...

8...

9 user: x: 100: 1:/home/user:/bin/bash

Next login, we can find that bash is used by default.

By default, the bash shell prompt is:

1. bash-3.00 $

2 bash-3.00 #

It can be "gorgeous" to express the current version of bash and whether it is out of the root, there is no other information, you can refer to this Article "Tips: Magic Tips", it is very detailed.

In the initial stage, first define the primary prompt:

1> export PS1 = "V890>"

2 V890>

3 V890> export PS1 = "Good Luck #"

4 Good Luck #

5 Good Luck # export PS1 = ">"

6>

You can change the prompt by modifying the variable PS1, but this is far from enough. After all, the prompt is static and we need a dynamic prompt. Let's take a look at the following conversion table:

01 \ a ASCII Bell character (you can also type \ 007)

02 \ d "Wed Sep 06" format date

03 \ e ASCII escape characters (you can also type \ 033)

04 \ h the first part of the Host Name (for example, "mybox ")

05 \ H host full name (for example, "mybox.mydomain.com ")

06 \ j number of processes suspended by ^ Z in this shell

07 \ l terminal device name of the shell (for example, "ttyp4 ")

08 \ n line break

09 \ r carriage return

10 \ s shell Name (such as "bash ")

11 \ t 24-hour time (for example, "23:01:01 ")

12 \ T 12-hour time (for example, "11:01:01 ")

13 \ @ 12-hour time with am/pm

14 \ u User Name

15 \ v bash version (e.g. 2.04)

16 \ V Bash version (including Patch Level )? /Td>

17 \ w current working directory (for example, "/home/drobbins ")

18 \ W "basename" of the current working directory (for example, "drobbins ")

19 \! Position of the current command in the History buffer zone

20 # command number (as long as you type the content, it will accumulate at each prompt)

21 \ $ if you are not a Super User (root), insert a "$"; if you are a super user, a "#" is displayed "#"

22 \ xxx insert an ASCII character represented by a three-digit xxx (with zero instead of unused digits, for example, "\ 007 ")

23 \ backslash

24 \ [this sequence should appear before the Character Sequence without moving the cursor (such as the color escape sequence. It enables bash to correctly calculate the line feed.

25 \] This sequence should appear after the non-printable character sequence.

Generally, I want to see at the first glance what users I am, what servers I am on, and the current directory through a prompt, which is actually the default bash prompt in Linux, we can set the prompt as follows:

1> export PS1 = "\ u \ H \ W \ $"

2 root V890 etc $

3 root V890 etc $

Now the prompt has the information we need, but it looks stupid. We need to beautify it. just copy the Linux bash prompt:

1> export PS1 = "[\ u @ \ H \ W] \ $"

2 [root @ V890 etc] $

3 [root @ V890 etc] $

Till now, we are still in the black and white stages. If the prompt is also colored, it will become more eye-catching. Can we make the prompt color? The answer is yes, but only if your client is supported.

The so-called coloring is just to add some terminal-recognizable "color escape characters". The format of "color escape characters" is as follows:

1 \ e [___ m

The "color Escape Character" used for resetting is:

1 \ e [0 m

Refer to the following color table:

Finally, I set my prompt to this:

Export PS1 = "[\ e [31m \ u \ e [0m @ \ e [33m \ H \ e [0 m \ e [36m \ W \ e [0 m] \ $"

Although it seems confusing, the principle is the same as that of HTML, and the corresponding content is clamped with special "tags.

To highlight the color, I added the color code as follows:

There is no reason to enter export xxxxxx every time after login, So modify the/etc/profile file and add the following two lines:

1 export PS1 = "[\ [\ e [31m \ u \ e [0m \] @ \ e [33mV890 \ e [0 m \ e [36m \ W \ e [0 m] \ $"

2 export PS2 = "[\ [\ e [31m \ u \ e [0m \] @ \ e [33mV890 \ e [0 m \ e [36m \ W \ e [0 m]>"

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.