Block Comments in a Shell Script

后端 未结 12 1219
小鲜肉
小鲜肉 2020-12-02 03:36

Is there a simple way to comment out a block of code in a shell script?

12条回答
  •  情话喂你
    2020-12-02 04:21

    A variation on the here-doc trick in the accepted answer by sunny256 is to use the Perl keywords for comments. If your comments are actually some sort of documentation, you can then start using the Perl syntax inside the commented block, which allows you to print it out nicely formatted, convert it to a man-page, etc.

    As far as the shell is concerned, you only need to replace 'END' with '=cut'.

    echo "before comment"
    : <<'=cut'
    =pod
    
    =head1 NAME
       podtest.sh - Example shell script with embedded POD documentation
    
    etc.
    
    =cut
    echo "after comment"
    

    (Found on "Embedding documentation in shell script")

提交回复
热议问题