with the previous PowerShell foundation, today we are going to learn a usage that can greatly improve the efficiency of PowerShell--variables
Jan said, the variable is a box with a name in memory ~~~~~ you can put everything you want to store in this " box ". Then visit the box by name.
During the access process, you can store, add, or retrieve things from the inside.
These things always reside in the box. and allows you to use them over and over again.
The procedure for defining a variable is as follows: The variable starts with the $ symbol, and then any name you want is entered.
very simple, when you want to use only need to re-enter the $var can be used
Of course, the variable can not only enter simple characters, but also can directly assign the result of the command to the variable
and even piping.
By calling variables, we can put frequently used information into variables to facilitate the use of subsequent commands, without having to enter each time.
When re-use, there are a few points to note:
Variable names usually contain letters, numbers, and underscores
You can include spaces, but you must enclose them in curly braces, and it is not recommended to name them.
When you close PowerShell, all the variables you create will be emptied
In addition to the custom variables, there are some variables built into PowerShell, you can view through get-variable, when defining variable names, be careful not to conflict with the built-in variable names
Now that you're done with the definition, here's a quick introduction to the variable type, usually with a character string that satisfies most of the requirements, but sometimes you need to limit the number, or the date, so long you need to force the declaration of the variable type.
Mandatory declarations only need to be preceded by parentheses [] when defining variables, and then by writing variable types
Like what
If the input data does not match the declared variable type, an error is generated and the value cannot be assigned
The following common data types are described here, such as
All right, today's three minutes to this, you hands up ~ ~
PowerShell variable--powershell three min (vii)