Find 167 I don’t want to have to check out every directory in the tree I give to find—that should be find’s job, dammit. I don’t want to mung the system software every time misfeatures like this come up. I don’t want to waste my time fighting SUN or the entire universe of Unix weeniedom. I don’t want to use Unix. Hate, hate, hate, hate, hate, hate, hate. —Ken (feeling slightly better but still pissed) Writing a complicated shell script that actually does something with the files that are found produces strange results, a sad result of the shell’s method for passing arguments to commands. Date: Sat, 12 Dec 92 01:15:52 PST From: Jamie Zawinski jwz@lucid.com Subject: Q: what’s the opposite of ‘find?’ A: ‘lose.’ To: UNIX-HATERS I wanted to find all .el files in a directory tree that didn’t have a corresponding .elc file. That should be easy. I tried to use find. What was I thinking. First I tried: % find . -name ’*.el’ -exec ’test -f {}c’ find: incomplete statement Oh yeah, I remember, it wants a semicolon. % find . -name ’*.el’ -exec ’test -f {}c’ \ find: Can’t execute test -f {}c: No such file or directory Oh, great. It’s not tokenizing that command like most other things do. % find . -name ’*.el’ -exec test -f {}c \ Well, that wasn’t doing anything… % find . -name ’*.el’ -exec echo test -f {}c \ test -f c test -f c test -f c test -f c
168 csh, pipes, and find ... Great. The shell thinks curly brackets are expendable. % find . -name ’*.el’ -exec echo test -f ’{}’c \ test -f {}c test -f {}c test -f {}c test -f {}c ... Huh? Maybe I’m misremembering, and {} isn’t really the magic “substitute this file name” token that find uses. Or maybe… % find . -name ’*.el’ \ -exec echo test -f ’{}’ c \ test -f ./bytecomp/bytecomp-runtime.el c test -f ./bytecomp/disass.el c test -f ./bytecomp/bytecomp.el c test -f ./bytecomp/byte-optimize.el c ... Oh, great. Now what. Let’s see, I could use “sed…” Now at this point I should have remembered that profound truism: “Some people, when confronted with a Unix problem, think ‘I know, I’ll use sed.’ Now they have two problems.” Five tries and two searches through the sed man page later, I had come up with: % echo foo.el | sed ’s/$/c/’ foo.elc and then: % find . -name ’*.el’ \ -exec echo test -f `echo ’{}’ \ | sed ’s/$/c/’` \ test -f c test -f c test -f c ... OK, let’s run through the rest of the shell-quoting permutations until we find one that works.
Previous Page Next Page