除非帮助注释从脚本的第一行开始,否则 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
请注意,这两种语法都有问题:
#!/usr/bin/env pwsh
# .SYNOPSIS
# This does a thing
这绝对是一个错误。 然而 ...
您只需要在 shebang 和解决它的帮助之间留一个空行。
这是因为连续的评论跨度都组合在一起,所以帮助系统认为shebang和概要是相同的评论吗?
最有用的评论
这绝对是一个错误。 然而 ...
您只需要在 shebang 和解决它的帮助之间留一个空行。