This solution doesn't adhere to guideline #2 — or does being vaguely sandwich-shaped count? I went on a kind of palindrome theme at the beginning, but I could only find so many ways to make lines symmetric without resorting to lame real code # ecod laer
. I didn't take guideline #1 very seriously, aesthetics comes first.
Remember that it's a makefile; the 3 successive lines beginning with if
, rm
and echo
begin with a tab. The other indented lines begin with spaces.
me : mr ; env | grep -q DO_US || rm -- mr || SU_OD q- perg | vne ; rm : em
.SILENT:##:TNELIS.
. = a. .a = .
$(.:.=):;:>$@
sandwich:
if expr>/dev/null $$(id -u); then echo 'What? Make it yourself'; fi
rm f- a me mr 2>/dev/null
echo Okay
mr : ; true : ; touch me : em f- mr || rm -f me : em hcuot ; : eurt ; : rm
Usage (the commands can be issued in any order):
$ sudo make me a sandwich
Okay
$ sudo make me sandwich
make: *** [sandwich] Error 1
$ sudo make a sandwich
make: *** [sandwich] Error 1
$ sudo make sandwich
make: *** [sandwich] Error 1
$ make me a sandwich
What? Make it yourself
make: *** [sandwich] Error 1
As for guideline #3, this isn't cleverly hidden, just slightly weirdly. Some hints:
There are two different tests: one search for SUDO_USER
, and one test of whether id -u
prints 0. Do you see why What?
is not printed for root? Do you see how the lack of SUDO_USER
causes Okay
not to be printed?
make
. \$\endgroup\$ – ugoren Jul 31 '13 at 5:53