make me a sandwich

xkcd 149. I was hungry.

Figure 1: contents of a file named Makefile.

For a smidgeon of educational content, note the use of $EUID (effective user ID) rather than $UID (real user ID). I consider it a design mistake that real user ID has a shorter name in most environments, despite effective user ID almost always being what you should use. See Wikipedia on user identifiers for a fair summary of the situation.

.PHONY: me a sandwich sandwich. ME A SANDWICH SANDWICH.

me a ME A:

sandwich sandwich.:
	@test $$EUID -ne 0 && echo "What? Make it yourself." || echo "Okay."

	@test $$EUID -ne 0 && echo "WHAT? MAKE IT YOURSELF." || echo "OKAY."

Figure 2: xkcd 149, Sandwich.

Note that although I made the Make targets support uppercase use, you’ll need something like alias MAKE=make to be able to type MAKE, and getting SUDO MAKE going is a more complicated exercise left to the reader.


Hardly the first implementation, but as I say, I was hungry.