Home > Blockchain >  Comment in Multi-line bash commands makefile
Comment in Multi-line bash commands makefile

Time:01-18

Assume you have a makefile of the form

<line n content>    \
<line n 1 content>  \
<line n 2 content>  \
<line n 3 content>  

and you would like the shell to receive

<line n content> <line n 2 content> <line n 3 content> (note: <line n 1 content> is missing in the desired output!)

How do you correctly (if possible) comment <line n 1 content> \ ?

This is not working:

<line n content>    \
# <line n 1 content>  \
<line n 2 content>  \
<line n 3 content>  \

Please note this: Comment multi-line bash statements has no answer and these: How to put a line comment for a multi-line command Commenting in a Bash script inside a multiline command refers on how to ADD a comment on a line, e.g.

<line n content>    \
<line n 1 content>  # comment for line n 1\
<line n 2 content>  \
<line n 3 content>  \

which differs from commenting an entire "line" (ok, a part of it)

CodePudding user response:

To give more context to my answer above:

You cannot add comments into makefile variable assignments. The make syntax doesn't allow it: make will first remove the backslashes and combine the lines. Only after that will it be checked for comments. So:

foo = foo # a comment \
      bar

is the same as:

foo = foo # a comment bar

In recipes, make doesn't interpret comments at all. It's up to the shell to decide how to interpret them. So for the shell, this works:

foo:
        echo one # a comment ; \
        echo two

That works how you'd "expect":

echo one # a comment; \
echo two
one
two

CodePudding user response:

I think you end up with something different because # is not possible after backslash.

I would recomend workaround:

par=()
par =("HI")
#par =("DAN")
par =("SUPER")
par =("YEAH")

par_one_line=$(IFS=' ' ; echo "${par[*]}")

echo $par_one_line

Basically create array of your params you would like to pass. Then join it by space. So if you comment some line of your parram it will work.

  • Related