PowerShell 运行以数字开头的命令


在PowerShell 2.0 中,如何你要运行以数字开头的命令或者函数,需要在前面加上“&”符号,例如,定义一个函数名为 3gumaolu:

PS D:\> Function 3GuMaolu()
>> {
>> Write-Host "三顾茅庐"
>> }
>>
PS D:\> 3GuMaolu
数字常量无效: 3。
所在位置 行:1 字符: 2
+ 3 <<<< GuMaolu
    + CategoryInfo          : ParserError: (3:String) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : BadNumericConstant

PS D:\> & 3GuMaolu
三顾茅庐

但是在PowerShell 3.0 中,已经不需要多此一举了,直接运行也能识别,从小处就可发现PowerShell 一直在朝着易用性方向进化。

原文链接:http://powershell.com/cs/blogs/tips/archive/2012/10/10/launching-commands-that-start-with-numbers.aspx

本文链接: https://www.pstips.net/powershell-launching-commands-that-start-with-numbers.html
请尊重原作者和编辑的辛勤劳动,欢迎转载,并注明出处!

关于 Mooser Lee

我是一个Powershell的爱好者,创建了PowerShell中文博客,热衷于Powershell技术的搜集和分享。本站部分内容来源于互联网,不足之处敬请谅解,并欢迎您批评指正。

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注