Powershell中的参数计算不正确
powershell中的参数不会像我期望的那样得到评估。 如果参数类型为object或string,则将数学表达式作为参数强制转换为字符串Powershell中的参数计算不正确,powershell,powershell-4.0,Powershell,Powershell 4.0,powershell中的参数不会像我期望的那样得到评估。 如果参数类型为object或string,则将数学表达式作为参数强制转换为字符串 Powershell代码:写入主机1+1 屏幕上打印的结果:1+1 预期结果:2 谁能告诉我为什么会这样? 这种行为背后的逻辑是什么 在语言规范中,它明确指出,如果参数类型为object,则值将按原样传递,而不进行强制转换 你能给我指一下描述这种行为的语言规范吗?因为我找不到它 注意:任何接受对象或字符串的函数都将遭受相同的行为。此链接 处理命令时,Wi
- Powershell代码:写入主机1+1
- 屏幕上打印的结果:1+1
- 预期结果:2
- In expression mode, character string values must be contained in
quotation marks. Numbers not enclosed in quotation marks are treated
as numerical values (rather than as a series of characters).
- In argument mode, each value is treated as an expandable string
unless it begins with one of the following special characters: dollar
sign ($), at sign (@), single quotation mark ('), double quotation
mark ("), or an opening parenthesis (().
Example Mode Result
------------------ ---------- ----------------
2+2 Expression 4 (integer)
Write-Output 2+2 Argument "2+2" (string)
Write-Output (2+2) Expression 4 (integer)
$a = 2+2 Expression $a = 4 (integer)
Write-Output $a Expression 4 (integer)
Write-Output $a/H Argument "4/H" (string)