Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set the PS1 default prompt in a Linux system

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Servers >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "how to set the PS1 default prompt in the Linux system". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

PS1 (the number 1 instead of the letter l). There may be a small difference in the special symbols in the PS1 variable of each version of bash. You can man bash it first. Here is the meaning represented by the default special symbols in the FC4 environment:

\ d: represents a date in the format of weekday month date, for example: "Mon Aug 1"

\ H: full host name. For example, if my machine name is fc4.linux, then this name is fc4.linux

\ h: take only the first name of the host. As in the example above, fc4,.linux is omitted.

\ t: display time in 24-hour format, such as HH:MM:SS

\ t: the display time is in 12-hour format

\ a: display time is 24 hours format: HH:MM

\ U: current user's account name

\ v: version information of BASH

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

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

\ #: the number of orders issued

\ $: prompt character. If it is root, the prompt is: #, and the average user is: $

The default PS1 content is PS1=' [\ u @\ h\ W]\ $', so the default prompt is: [root@linux ~] #.

To change enter at the shell prompt:

The code is as follows:

[root@web1177 ~] # PS1=' [\ u@\ h\ w\ #]\ $'

In this way, you can know which command you are entering.

Next we will discuss the variable assignment in SHELL. Let's take a look at the variable assignment in Bird's book:

1. Variables are linked with their contents with an equal sign (=).

two。 Space characters cannot be connected directly on both sides of the equal sign.

3. Variable names can only be letters and numbers, but numbers cannot be opening characters

4. If there is a space character in the assignment, you can use double quotation marks or single quotation marks to combine the contents of variables, but it should be noted that the special characters in double quotation marks can retain variable characteristics, but the special characters in single quotation marks are only general characters.

5. If necessary, special symbols (such as Enter, $,\, space,', etc.) need to be changed into general symbols with a backslash (\).

6. In a series of instructions, you need to provide information through other instructions, you can use the reference character (`command`); (especially note that `is the key to the left of numeric key 1 above the keyboard, not single quotation marks!)

7. If the variable is the content of the augmented variable, continue to add the content with double quotation marks and the name of the $variable such as "$PATH": / home

8. If the variable needs to be executed in other subroutines, you need to use export to change the variable into an environment variable, such as export PATH

9. Usually uppercase characters are system preset variables, self-setting variables can use lowercase characters to facilitate judgment (purely according to the user's interests and preferences)

10. The method to cancel a variable is: unset the variable name.

So in the PS1 setting, because there is a space in the middle, so we need to use single and double quotation marks, there is no need to use the result of the command, so there is no need for reference. We choose single quotation marks so that PS1 can directly accept pure characters, not characters that have a special meaning in SHELL, or variables that begin with $, so we can use single quotation marks, or double quotation marks.

This is the end of "how to set the PS1 default prompt in Linux system". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Servers

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report