我是Powershell的初学者,并且正在努力从我在Github上找到的某些代码中了解某些语法。我已经阅读了有关Powershell分配和switch语句的文档,并且无法理解此代码段中= $Yes
和= $No
的情况:
Switch ($Prompt3) {
Yes {
Stop-EdgePDF
Write-Output "Edge will no longer take over as the default PDF viewer."; = $Yes
}
No {
= $No
}
}
我无法找到对这种语法的任何引用,并且在脚本中似乎没有做任何事情。那为什么呢?
答案 0 :(得分:1)
在功能(或变量)名称中有许多有效的 个字符;其中包括=
符号。您正在观察的是函数或别名。
示例:
# standard function
function =
{
return $args
}
# accessing the function: drive
${Function:=} = {
return $args
}
# defining a new alias
New-Alias -Name = -Value Get-Variable
# using the Alias attribute
function Test-Thing
{
[Alias('=')]
param()
return $args
}
答案 1 :(得分:1)
更新:此问题已解决。
在我看来像the variable name that was getting the assignment was deleted in a change back in August。
$PublishSettings = $Yes
已更改为:
= $Yes
并且:
$PublishSettings = $No
已更改为:
= $No
看起来搜索和替换效果不佳。