或者使用"set-variable”命令:复制代码
- $StrUser = "MR"
需要注意的是,使用“set-variable”命令时在变量名前不需要使用“$”。复制代码
- set-variable -name StrUser -value "MaRui"
或者直接输入变量名,如:复制代码
- write-output $StrUser
运行结果:复制代码
- $StrUser
PS E:\> $StrUser = "MR" PS E:\> set-variable -name StrUser -value "MaRui" PS E:\> write-output $StrUser MaRui PS E:\> $StrUser MaRui |
int | 有符号,32bit |
long | 有符号,64bit |
double | 双精度64bit浮点 |
single | 单精度32bit浮点 |
string | unicode编码字符串 |
char | unicode编码字符,16bit |
byte | 无符号字符,8bit |
decimal | 十进制数,128bit |
array | 数组 |
xml | xml对象 |
hashtable | 哈希表 |
bool | true、false |
复制代码
- $strA = "Hello"
- $strB = "World!"
- $strC = $strA + $strB
- $strC
PS E:\> $strA = "Hello" PS E:\> $strB = "World!" PS E:\> $strC = $strA + $strB PS E:\> $strC HelloWorld! |
复制代码
- $strA = "hi! world!"
- $strB = $strA -replace "hi!", "Hello"
- $strB
PS E:\> $strA = "hi! world!" PS E:\> $strB = $strA -replace "hi!", "Hello" PS E:\> $strB Hello world! |
复制代码
- $strA = "MaRui"
- "This is $strA."
- 'This is $strA.'
PS E:\> $strA = "MaRui" PS E:\> "This is $strA." This is MaRui. PS E:\> 'This is $strA.' This is $strA. |
复制代码
- 5 + 100
- $x=200+1
- $x
- [int]$y=(7 + 13 * 2) / 10
- $y
PS E:\> 5 + 100 105 PS E:\> $x=200+1 PS E:\> $x 201 PS E:\> [int]$y=(7 + 13 * 2) / 10 PS E:\> $y 3 |
+ | 加 |
- | 减 |
* | 乘 |
/ | 除 |
% | 取余 |
= | 赋值 |
++ | 给变量加1,相当于+1 |
-- | 给变量减1,相当于-1 |
欢迎光临 批处理之家 (http://bbs.bathome.net/) | Powered by Discuz! 7.2 |