-1

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?

Michael
  • 6,823
  • 11
  • 54
  • 84
  • 2
    Please show how you are invoking it in your bash script. It will not be a shell variable if it is single-quoted, as in your example above; but it will if you put some different quotes around it. For example, `foo=$(perl -C -p -i -e 's/([\?\.\!])\n/$1 /g' html/數14.html)` is quoted by `$()`, which will expand `$1`, and you'd need to escape `$1` into `\$1`. – Amadan Jul 28 '16 at 07:38
  • Read this thread: [http://stackoverflow.com/questions/31557677/how-to-pass-a-regular-expression-as-a-parameter-to-a-perl-one-liner-in-a-bash-sc/31563152#31563152] – Poyke Jul 28 '16 at 07:41
  • 1
    Yes, sorry. It's not a bash script, it's a Makefile. :-| – Michael Jul 28 '16 at 07:43
  • 2
    Please avoid XY-questions. The answer is *very* different for Makefiles. – Amadan Jul 28 '16 at 07:45

1 Answers1

3

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.

Amadan
  • 191,408
  • 23
  • 240
  • 301