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
?
As @Philippe commented, the solution was to replace single dollar signs
$
with double dollar signs$$
. Thus my makefile became: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.