On Mon, Apr 11, 2011 at 12:23:15PM -0600, Bill Gradwohl wrote: > -----BEGIN PGP SIGNED MESSAGE----- > > I have a tiny script to prune empty directories from a structure. The > essential line is as follows: > > tree --noreport -dfi "${1}" | tac | sed 's/"/\\"/g;s/^/rmdir > - --ignore-fail-on-non-empty "/;s/$/"/'|bash
Not good. You're piping filenames into bash and letting bash parse them as commands. If a filename contains something like $(...) or `...` then yes, bash would perform a command substitution. Just do this instead: find . -type d -exec rmdir {} \; 2>/dev/null It's a bit of a hack; it relies on the fact that rmdir will fail on non-empty directories, so we don't have to CHECK them. It discards all errors, which is the hackish part. If this isn't good enough, learn find in more depth. http://mywiki.wooledge.org/UsingFind