tombre@crin.crin.fr (Karl Tombre) (12/16/87)
At logout time we often want to clear our directories. At the moment we have
a script doing this interactively :
-----
#!/bin/sh
echo -n "> Clean up (y/n) ?"
read r
if (test $y = "o") then
find $HOME \( -name core -o -name a.out -o -name '*.test' \
-o -name '_ted.sav*' -o -name '*.old' -o -name '.*.old' \
-o -name '*BAK' -o -name '*.CKP' -o -name '.*.BAK' \
-o -name '.*.CKP' -o -name '#*' -o -name '*~' \
-o -name '.*~' -o -name 'saved_co*' -o -name dead.letter \) \
-exec rm -i {} \;
fi
# Notice we have both GNUemacs and Unipress ;-)
-----
I wanted to complete this tool by adding a -b switch for doing it in
background. That is, without the -b it would work like before, with -b it
would do a
nohup find .... &
The easy solution, and the only one I managed to get working, is to
duplicate the whole find command twice, one for -b, one without.
I wanted to define a variable. First, i tried :
CLEAN="find $HOME \( -name core -o -name a.out -o -name '*.test' \
-o -name '_ted.sav*' -o -name '*.old' -o -name '.*.old' \
-o -name '*BAK' -o -name '*.CKP' -o -name '.*.BAK' \
-o -name '.*.CKP' -o -name '#*' -o -name '*~' \
-o -name '.*~' -o -name 'saved_co*' -o -name dead.letter \)"
and called by :
$CLEAN -exec /bin/rm -i {} \;
or
nohup $CLEAN -exec /bin/rm -f {} \; &
It didn't work, it seemed that the special characters ', * and \ were
interpreted wrong. I tried of course to quote them and so on, without
success.
I then tried :
FILES="-name core -o -name a.out -o -name '*.test' \
-o -name '_ted.sav*' -o -name '*.old' -o -name '.*.old' \
-o -name '*BAK' -o -name '*.CKP' -o -name '.*.BAK' \
-o -name '.*.CKP' -o -name '#*' -o -name '*~' \
-o -name '.*~' -o -name 'saved_co*' -o -name dead.letter"
with
find \( $FILES \) ...
and I removed even the \ to have $FILES on one line only. No success. The
best I achieved was no error message, the find ran for a while, but removed
nothing (or maybe only the core files).
I suspect it to be an interference between the shell script, the special
characters, the variable expansion and the globbing !!! Is there a solution
or shall I stick to the inelegant solution of duplicating the command ?
--- Karl Tombre @ CRIN (Centre de Recherche en Informatique de Nancy)
EMAIL : tombre@crin.crin.fr -- tombre@crin.UUCP
POST : Karl Tombre, CRIN, B.P. 239, 54506 VANDOEUVRE CEDEX, France
PHONE : +33 83.91.21.25