You can also use -mindepth 1 in find and skip the first if statement. And instead of ls and then reading $?, you can use the built-in [ -f $SPECIAL_FILE ] (see man test). You will also have issues with directories with spaces as it stands; quote at least the third FIND_BASE assignment and the $FIND_BASE in the find command. Quoting is always good. Until you know exactly when it's not needed: use it everywhere it is possible; every assignment, every variable call (not in the for statement as it stands, then you will only get a single iterator).
–
Daniel AnderssonMar 30 '12 at 15:27

2 Answers
2

only finds files of maximum path depth 1 under the argument directory.

Also: replace rm -rf with a simple echo when trying out changes, as you most probably do not want to find out the hard way that your changes are not what they are supposed to be.

-maxdepth 1 will make the script only look for the special file in the first sub directories, and if it is not found, delete them. If the special file resides deeper, you have to do a full depth check, but this solution fits my interpretation of your question in its original form.