Shell script multi-line comment

后端 未结 5 1918
傲寒
傲寒 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 10:03

    First, using here docs to comment code is really dirty! Use the # instead. If you want to comment multiple lines, use your editor. In vim (commenting lines from 10 to 15 for example):

    :10,15s/^/#
    

    However, to solve your current problem you need to enclose the starting here-doc delimiter in single quotes, like this:

    <<'COMMENT'
    ...
    COMMENT
    

    Using single quotes you tell bash that it should not attempt to expand variables or expression inside the here doc body.

提交回复
热议问题