Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: listing/deleting empty directories recursively



* Christian Taylor (2005-11-19 12:48 +0100)
> Thor Andreassen wrote:
>>> This should do the trick:
>>>
>>> for dir in `ls -ld **/*(/^F)`; do echo $dir > LOGFILE; rmdir $dir; done
>>
>> You should use double quotes (") around the dir variable if you have
>> dirnames with spaces (and some other chars), i.e. echo "$dir" and rmdir
>> "$dir".
> 
> That probably wouldn't work, since ls -ld prints a whole lot of additional 
> information that will be interpreted as directories to log and delete. It's 
> far simpler to do away with ls:
> 
> for dir in **/*(/^F); do print $dir >> LOGFILE; rmdir $dir; done

Exactly. Using "for x in $(ls)" or "for x in $(ls *)" instead of "for
dir in *" is a common mistake (mentioned in "From bash to zsh").
 
> or with the alternative syntax I really like:
> 
> for dir (**/*(/^F)) { print $dir >> LOGFILE; rmdir $dir }
> 
> As far as I can see, filenames generated this way are already quoted 
> correctly, so spaces and special characters shouldn't be an issue.

Sorry, but it completely the other way round: the filenames are not
split (shwordsplit) so there's no need to quote them.

That's one major reason for the superiority of zsh to other shells
like bash.



Messages sorted by: Reverse Date, Date, Thread, Author