简体   繁体   English

PowerShell别名-名称无限制

[英]PowerShell alias - No restrictions on name

I have written a simple SetDifference function, by using the Compare-Object function: 我通过使用Compare-Object函数编写了一个简单的SetDifference函数:

Function SetDifference {
    param(
    [Parameter(Mandatory=$true)]$ReferenceObject,
    [Parameter(Mandatory=$true)]$DifferenceObject
    )

    Compare-Object $ReferenceObject $DifferenceObject | 
    Where-Object { $_.SideIndicator -eq '<=' } | 
    ForEach-Object { $_.InputObject }
}

I've noticed that ANY alias can be used without PowerShell complaining: 我注意到可以使用ANY别名而不会抱怨PowerShell:

Set-Alias '\' 'SetDifference'
Set-Alias '.' 'SetDifference'
Set-Alias '+' 'SetDifference'

Shouldn't there be restrictions on what the alias name can be - to stop you from using symbols that are already part of PowerShell syntax? 别名名称可以不受限制吗?要阻止您使用已经是PowerShell语法一部分的符号?

You should get an error, when using ie the '+'. 使用“ +”时,您应该得到一个错误。

See here , you should follow this: "You can use any alphanumeric characters in an alias, but the first character cannot be a number." 参见此处 ,您应遵循以下步骤:“您可以在别名中使用任何字母数字字符,但第一个字符不能为数字。”

Also resuing an already defined alias will throw an error. 同样,恢复已经定义的别名将引发错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM