Shell script multi-line comment

后端 未结 5 1888
傲寒
傲寒 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:02

    Traditional UNIX shell doesn't have multiline comment support. What you're doing here is using a so-called "HERE document" without using its value, a common hack to get multiline comment like behaviour.

    However, patterns inside the the HERE document are still evaluated, which means that your $(…) is executed. But since build_branch_tag has not been defined before, it will evaluate to an empty string, and the shell will thus execute sed s///g.

    You can use a different hack:

    : '
    Bla bla, no $expansion is taking place here.
    '
    

    What this is doing: the : is a no-op command, it simply does nothing. And you're passing it an argument which is a string '…'. Inside the single quotes, no expansion/evaluation is taking place. Beware of ' inside the "commented out" region, though.

提交回复
热议问题