1. What is a variable?
X = 200
The variable on the left of the equal sign and the variable content on the right of the equal sign
Variable Variability
2. Functions of Variables
Replaces complex and easy-to-change content with simple characters
3. variable definition
$ Testdata ="Is Test"
In this way, a variable testdata is defined.
When using variables, you must add the "$" character.
$ Echo$ Testdata
Output "is test"
You need to append other strings to the output. You can use $ {Variable}
$ Echo this is$ {Testdata}
Output "this is test"
4. Cancel variable settings
Use the $ unset command to cancel variable settings.
$ Unset testdata
The variable name is directly followed by the command unset. Note that there is no "$" symbol
5. variable definition rules
1) There cannot be spaces on both sides of the equal sign
2) The variable must be assigned a value during initialization. The variable that has not been assigned a value is null, but the variable that has not been assigned a value in ECHO does not report an error and no output.
3) The variable name can only consist of letters, numbers, and short underscores (_), and cannot start with a number.
4) when the variable content contains white spaces, double quotation marks (") or single quotation marks (") can be used to enclose the content.
However, special characters such as $ in double quotation marks retain the original features, such
$ Testdata ="Home is $ home"
$ Echo$ Testdata
Output "Home is/users/"
Special characters in single quotes are converted to plain text, for example
$ Testdata = 'home is$ Home'
$ Echo$ Testdata
Output "Home is $ home"
5) You can use the "\" character to escape special characters (such as enter, $, \, blank characters, and so on ).
$ Testdata = home \ is \ home
$ Echo$ Testdata
The preceding escape is a blank character, so no error is reported. The output is "home is home"
6. Environment Variables
1) run the $ ENV command to view all the defined environment variables. env is the abbreviation of environment.
$ ENV
You can also view it using $ export.
2) run the $ set command to view all environment variables and custom variables.
$ Set
3) Unlike custom variables, environment variables are usually expressed in uppercase letters, such as path, home, mail, and shell.
View environment variable path
$ Echo$ Path
Path: Specifies the path of the executable file. The directory is separated by ":" Before the directory. When a command orProgramThe program is searched based on the directory defined by the path.
Random: Random Number,0 ~ Between 32767