1

I have a command which runs successfully from the command line and turns this:

1 first line
2 second line
3 third line
4 fourth line
extra bit
5 fifth line
6 sixth line

into this:

1 first line
2 second line
3 third line
4 fourth line; extra bit
5 fifth line
6 sixth line

Here is the command:

printf "%s\n" '2,$g/^[^0-9]/-1s/$/; /\' '.,+1j' w | ed -s file

It works when run from the command line. However, when I try to run the same thing from a makefile, file is not changed and I get this error message:

$ make
printf "%s\n" '2,/^[^0-9]/-1s/; /\' '.,+1j' w | ed -s file
?
make: *** [make] Error 2

Here is the makefile, containing that same command:

make:
        printf "%s\n" '2,$g/^[^0-9]/-1s/$/; /\' '.,+1j' w | ed -s file

How can I get this command to run with make?

mherzl
  • 5,624
  • 6
  • 34
  • 75
  • 2
    In your makefile, try to put $$ where you have a single $. – Philippe Jul 19 '20 at 17:23
  • 3
    https://www.gnu.org/software/make/manual/html_node/Rule-Syntax.html : _Because dollar signs are used to start make variable references, if you really want a dollar sign ... you must write two of them, ‘$$’_ – MadScientist Jul 19 '20 at 18:11

1 Answers1

1

As @Philippe commented, the solution was to replace single dollar signs $ with double dollar signs $$. Thus my makefile became:

make:
        printf "%s\n" '2,$$g/^[^0-9]/-1s/$$/; /\' '.,+1j' w | ed -s file

As explained in the make documentation, single dollar signs are expanded as 'variable and function references', so for a single dollar sign to be used as such it must be doubled.

mherzl
  • 5,624
  • 6
  • 34
  • 75