How to use sed in a Makefile
TL;DR: Use single quotes and use two $ signs. The expression is expanded twice, once by make
and once by bash
. The rest of this answer provides further context.
It might be the $ sign in the substitution that is interpreted by make as a variable. Try using two of them like .*$$#public_demo. Then make will expand that to a single $.
EDIT: This was only half the answer. As cristis answered: the other part is that one needs to use single quotes to prevent bash from expanding the $ sign too.
The make
version in my machine is:
$ make --version
GNU Make 3.81
Copyright (C) 2006 Free Software Foundation, Inc.
This is free software; see the source for copying conditions.
There is NO warranty; not even for MERCHANTABILITY or FITNESS FOR A
PARTICULAR PURPOSE.
This program built for x86_64-redhat-linux-gnu
And the sed
version:
$ sed --version
GNU sed version 4.2.1
I must add backslash for $
to prevent sed taking it as end of line:
cat sys.conf | sed -e 's#^public_demo[\s=].*\$$#public_demo=0#' >sys.conf.temp
I suggest you use single quotes instead of double quotes, the $
might be processed as a special char by make before running sed:
cat sys.conf | sed -e 's#^public_demo[\s=].*$#public_demo=0#' >sys.conf.temp;