Using sh in makefiles

Guy Harris guy at sun.uucp
Sun Jun 29 16:43:48 AEST 1986


> Would like advice on how to use shell commands (such as if...) in
> makefiles.  I know that it all has to be on one line, but the only way I
> can make a command work is through a kludge like:
> 
> test:
> 	echo "if x;then y;fi" | sh
> 
> which seems pretty roundabout.  Is this the only way to do it?

Nope.  If "make" recognizes any of a number of special characters in a
command line, it passes that command line to "sh" rather than running the
command itself.  ";" is one of those characters, so

	test:
		if x; then y; fi

is sufficient.

Furthermore, they must all be on one "line"; however, "make"s idea of a
"line" can be altered by using escaped newlines:

	test:
		if x; then \
			y; \
		fi

will work.
-- 
	Guy Harris
	{ihnp4, decvax, seismo, decwrl, ...}!sun!guy
	guy at sun.com (or guy at sun.arpa)



More information about the Comp.unix mailing list