Shell script multi-line comment

后端 未结 5 1890
傲寒
傲寒 2021-01-03 09:32

I am having a large shell script file. At times while doing modification I want to comment out part of it. But commenting line as shown in the below example is giving me e

5条回答
  •  迷失自我
    2021-01-03 09:59

    You can turn parameter substitution off inside a here document like this:

    <<"Endofmessage"
    

    or

    <<'Endofmessage'
    

    or

    <<\Endofmessage
    

    Here Documents

    This type of redirection instructs the shell to read input from the current source until a line containing only delimiter (with no trailing blanks) is seen. All of the lines read up to that point are then used as the standard input for a command. The format of here-documents is:

    <<[-]word here-document delimiter No parameter expansion, command substitution, arithmetic expansion, or pathname expansion is performed on word. If any characters in word are quoted, the delimiter is the result of quote removal on word, and the lines in the here-document are not expanded. If word is unquoted, all lines of the here-document are subjected to parameter expansion, command substitution, and arithmetic expansion. In the latter case, the character sequence \ is ignored, and \ must be used to quote the characters \, $, and `. If the redirection operator is <<-, then all leading tab characters are stripped from input lines and the line containing delimiter. This allows here-documents within shell scripts to be indented in a natural fashion.

    And maybe something that you may also like: I prefer to do multiline comments in my bash script with the nodepad++ shortcut ctrl+Q (toggle comment).

提交回复
热议问题