How do you comment out code in PowerShell?

前端 未结 10 1557
傲寒
傲寒 2020-12-12 08:59

How do you comment out code in PowerShell (1.0 or 2.0)?

相关标签:
10条回答
  • 2020-12-12 09:44

    Single line comments start with a hash symbol, everything to the right of the # will be ignored:

    # Comment Here
    

    In PowerShell 2.0 and above multi-line block comments can be used:

    <# 
      Multi 
      Line 
    #> 
    

    You could use block comments to embed comment text within a command:

    Get-Content -Path <# configuration file #> C:\config.ini
    

    Note: Because PowerShell supports Tab Completion you need to be careful about copying and pasting Space + TAB before comments.

    0 讨论(0)
  • 2020-12-12 09:44

    You can make:

     (Some basic code) # Use "#" after a line and use:
    
     <#
        for more lines
        ...
        ...
        ...
        ..
        .
     #>
    
    0 讨论(0)
  • 2020-12-12 09:46

    Use a hashtag followed by a white-space(!) for this:

     # comment here
    

    Do not forget the whitespace here! Otherwise it can interfere with internal commands.

    E.g. this is NOT a comment:

    #requires -runasadmin
    
    0 讨论(0)
  • 2020-12-12 09:52

    You use the hash mark like this

    # This is a comment in Powershell
    

    Wikipedia has a good page for keeping track of how to do comments in several popular languages

    http://en.wikipedia.org/wiki/Comparison_of_programming_languages_(syntax)#Comments

    0 讨论(0)
提交回复
热议问题