Powershell: 基于注释的帮助不适用于以 shebang 开头的脚本

创建于 2017-11-16  ·  3评论  ·  资料来源: PowerShell/PowerShell

除非帮助注释从脚本的第一行开始,否则 PowerShell 不会解析脚本的基于注释的帮助。 这会阻止使用shebang 的脚本通过Get-Help

如果脚本文件以#!开头,PowerShell 应该跳过它的第一行。

重现步骤

使用shebang创建一个名为thing.ps1的新脚本:

#!/usr/bin/env pwsh
<#
.SYNOPSIS
This does a thing
#>

预期行为

PS> Get-Help thing.ps1

NAME
    /Users/aaron/src/thing.ps1

SYNOPSIS
    This does a thing

…

实际行为

PS> Get-Help thing.ps1
thing.ps1
…

环境数据

PS> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.0.0-beta.9
PSEdition                      Core
GitCommitId                    v6.0.0-beta.9
OS                             Darwin 16.7.0 Darwin Kernel Version 16.7.0: Thu Jun 15 17:36:27 PDT 2017; root:xnu...
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0
Issue-Enhancement WG-Interactive-HelpSystem

最有用的评论

绝对是一个错误。 然而 ...

您只需要在 shebang 和解决它的帮助之间留一个空行。

所有3条评论

请注意,这两种语法都有问题:

#!/usr/bin/env pwsh
# .SYNOPSIS
# This does a thing

绝对是一个错误。 然而 ...

您只需要在 shebang 和解决它的帮助之间留一个空行。

这是因为连续的评论跨度都组合在一起,所以帮助系统认为shebang和概要是相同的评论吗?

此页面是否有帮助?
0 / 5 - 0 等级