Basic CentOS variable commands

Source: Internet
Author: User

Basic CentOS variable commands
1. Classification of Variables

1) User-Defined variables
2) environment variables: these variables mainly store data related to the operating environment of the system.
3) Location Parameter Variable: this variable is mainly used to pass parameters or data to the script. The variable name cannot be customized, and the variable function is fixed.
4) pre-defined variable: it is a variable defined in bash. The variable name cannot be customized, and the variable function is also fixed.

2. Custom Variables

The name consists of numbers, underscores, and letters, but cannot start with a number, such as "2Name"
1) There cannot be spaces on both sides of the variable equal sign
2) If spaces exist, enclose them ""
3) use the "\" Escape Character to invalidate special characters, for example, "\ $ name"
4) to overlay variables, you can use "$ variable name" or "$ {variable name}
5) If the command result is used as the variable value, the command is enclosed in reverse quotation marks (not recommended) or \ $ ().
6) we recommend that you use uppercase letters for environment variable names.
Aa = "test" echo $ aa is the output test
Aa = 123 aa = "$ aa" 456 what is output?
Set variable viewing command
Unset + variable name Delete variable command

3. Environment Variables

Exprot variable name = variable value application variable
Env query Variables
Unset Delete variable name
PATH: path of the system query command (default sorting and PATH are available for the system query command)
PATH = "$ PATH":/root variable superposition (temporary)
Environment Variable PS1:
Define the variables of the system prompt, that is, [host name @…] # That Thing
The current configuration command is displayed in the query:Echo $ PS1
The format of replacement is:PS1 = '[...... ] $ '(Remember to leave a space at the end to better enter the command)
Options include:
\ D Display date, in the format of "day of the week"
\ H indicates the abbreviated host name. For example, the default host name is "localhost"
\ T displays the 24-hour time in the format of "HH: MM: SS"
\ T displays the 12-hour time in the format of "HH: MM: SS"
\ A displays the 24-hour time in the format of "HH: MM"
\ U display current user name
\ W displays the complete name of the current directory
\ W displays the last directory of the current directory
# Number of commands executed
\ $ Prompt. If it is a root user, "#" is displayed. If it is a common user, "$" is displayed"

4. location parameters and predefined

Location parameters are generally used in shell
$ Nn is a number, 0 represents the command itself, and more than 10 parameters are enclosed in braces
$ * Indicates that all parameters in the command line are regarded as a whole.
$ @ Indicates all parameters, but each parameter is treated differently
$ # The predefined Number of command lines and parameters can be used with echo.
$? Judge the previous command. If the value is 0, the command is correctly executed. If the value is not 0, the command is incorrect (the specific number is determined by the command)
$ Current process ID
$! The last process number running in the background

5. declare declares the variable type.

Declare [+/-] [Option] variable name
-: Set the type attribute for the variable.
+: Cancel setting the type attribute for the variable.
-I declare the variable as an integer.
-X declares variables as environment variables => exprot
-P: shows the declared type of the specified variable.

6. expr or let numerical calculation tool

For example:
Aa = 11 bb = 22
Dd = $ (expr $ aa + $ bb) note! + There must be spaces on both sides
Commonly used "$ (operation)" or "$ [operation]"
For example, ff =$ ($ aa + $ bb ))
Operator priority:

Variable test and content replacement: test the content of the variable or whether to replace the variable. The output x shows the result.

7. environment variable configuration

Source configuration file and. Configuration File
The above two configuration files take effect directly without restarting (note that there is a point)
The following are five default configuration files:
/Etc/profile. d/*. sh (all ends with. sh)
All three are valid for all users.
~ /. Bash_profile
~ /. Bashrc
Under USER commands, these two are valid for specific users

Environment variable configuration file that takes effect upon cancellation:
~ /. Bash_logout
~ /. Bash_history

8. shell login information

(Before login)
/Etc/issue (local logon)
/Etc/ (Welcome to remote terminals)
Ps. The ssh configuration file is required./Etc/ssh/sshd_config
# Banner ............ AddBanner/etc/
Restart again,Service sshd restart
/Etc/motd: Run vim directly to display the prompt information after logon)

Variable is indeed a difficult part, not only a lot of configuration files, but also need to be familiar with the heart, come on.

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: 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.