ugh.book

(singke) #1

170 csh, pipes, and find


Hey, that last one was kind of close. Now I just need to...

% find. -name ’*.el’ \
-exec echo test -f ’`echo {} | \
sed "s/$/c/"`’ \;
test -f `echo {} | sed "s/$/c/"`
test -f `echo {} | sed "s/$/c/"`
test -f `echo {} | sed "s/$/c/"`
...

Wait, that’s what I wanted, but why isn’t it substituting the filename
for the {}??? Look, there are spaces around it, what do you want, the
blood of a goat spilt under a full moon?

Oh, wait. That backquoted form is one token.

Maybe I could filter the backquoted form through sed. Um. No.

So then I spent half a minute trying to figure out how to do some-
thing that involved “-exec sh -c ...”, and then I finally saw the light,
and wrote some emacs-lisp code to do it. It was easy. It was fast. It
worked.

I was happy. I thought it was over.

But then in the shower this morning I thought of a way to do it. I
couldn’t stop myself. I tried and tried, but the perversity of the task
had pulled me in, preying on my morbid fascination. It had the same
attraction that the Scribe implementation of Towers of Hanoi has. It
only took me 12 tries to get it right. It only spawns two processes per
file in the directory tree we're iterating over. It’s the Unix Way!

% find. -name ’*.el’ -print \
| sed ’s/^/FOO=/’|\
sed ’s/$/; if [! -f \ ${FOO}c ]; then \
echo \ $FOO ; fi/’ | sh

BWAAAAAHH HAAAAHH HAAAAHH HAAAAHH
HAAAAHH HAAAAHH HAAAAHH HAAAAHH HAAAAHH!!!!

—Jamie
Free download pdf