Michael Michael - 4 months ago 22
Perl Question

Using $1 in regexp within a Makefile

I try to do a replace with following perl command:

perl -C -p -i -e 's/([\?\.\!])\n/$1 /g' html/數14.html


The result is fine when I call it from the command line. When I call it from within a Makefile it doesn't work. Apparently the $1 is interpreted as shell variable.

In the Makefile it looks like this:

數14.html: 數14.adoc 40_2064_Im\ Strand-Appartment.adoc 41_2064_Ein\ Plan.adoc 42_1915_In\ einer\ Suppenküche.adoc
asciidoctor -D html parts/數14.adoc
perl -C -p -i -e 's/([\?\.\!])\n/$1 /g' html/數14.html


How can I have normal regexp behaviour here?

Answer

Makefiles always interpret $ sequences before executing commands, disregarding any quoting. In order to escape $ in a Makefile, write it as $$ - that will result in a single $ in the command.

Comments