tags:

views:

28

answers:

3

I have tried putting the following in my Makefile:

@if [ $(DEMO) -eq 0 ]; then \
    cat sys.conf | sed -e "s#^public_demo[\s=].*$#public_demo=0#" >sys.conf.temp; \
else \
    cat sys.conf | sed -e "s#^public_demo[\s=].*$#public_demo=1#" >sys.conf.temp; \
fi

but when I run make, I get the following error:

sed: -e expression #1, char 30: unterminated `s' command

If I run the exact lines that contain sed in the console, they behave correctly.

Why am I getting this error and how can the problem be fixed?

+1  A: 

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;
cristis
I used single quotes in the first place and switched to double quotes because I, too, have thought that the single quotes were the problem.
Tom
Actually, I think cristis is correct, regardless of whether my answer is correct or not. $ will be expanded twice, I think: Once in the makefile, per my answer, and once by bash. Using single quotes will prevent bash from expanding the $, but not make.
Erik Edin
Actually you were BOTH right. Using single quotes and $$ fixed the problem. Whose answer do I accept now?
Tom
Good question. I can edit my post and reference cristis answer.
Erik Edin
A: 

Use something else than # to separate parts.

Sjoerd
I used / in the first place and switched to # because I, too, have thought that the separator was the problem.
Tom
+3  A: 

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.

Erik Edin