你如何在PowerShell(1.0或2.0)中注释掉代码?
在PowerShell V1中,只有#
才能在评论后生成文本。
# This is a comment in Powershell
在PowerShell V2中,<# #>
可用于块注释,更具体地用于帮助注释。
#REQUIRES -Version 2.0
<#
.SYNOPSIS
A brief description of the function or script. This keyword can be used
only once in each topic.
.DESCRIPTION
A detailed description of the function or script. This keyword can be
used only once in each topic.
.NOTES
File Name : xxxx.ps1
Author : J.P. Blanc ([email protected])
Prerequisite : PowerShell V2 over Vista and upper.
Copyright 2011 - Jean Paul Blanc/Silogix
.LINK
Script posted over:
http://silogix.fr
.EXAMPLE
Example 1
.EXAMPLE
Example 2
#>
Function blabla
{}
有关.SYNOPSIS
和.*
的更多解释,请参阅about_Comment_Based_Help。
备注:这些函数注释由Get-Help
CmdLet使用,可以放在关键字Function
之前,或者放在代码本身之前或之后的{}
中。
你使用这样的哈希标记
# This is a comment in Powershell
维基百科有一个很好的页面,可以跟踪如何用几种流行语言进行评论
http://en.wikipedia.org/wiki/Comparison_of_programming_languages_(syntax)#Comments
这是#
。
有关特殊字符,请参阅PowerShell - Special Characters And Tokens。
单行注释以hash symbol开头,#
右侧的所有内容都将被忽略:
# Comment Here
在PowerShell 2.0及更高版本中,可以使用多行块注释:
<#
Multi
Line
#>
您可以使用块注释在命令中嵌入注释文本:
Get-Content -Path <# configuration file #> C:\config.ini
注意:因为PowerShell支持Tab Completion,所以在评论之前需要注意复制和粘贴Space + TAB
。
这里
# Single line comment in Powershell
<#
--------------------------------------
Multi-line comment in PowerShell V2+
--------------------------------------
#>
你(们)能做到:
(Some basic code) # Use "#" after a line and use:
<#
for more lines
...
...
...
..
.
#>