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

quick and dirty test for empty directory



Best advice googling for such a test is this:

                [ -d "$dir" ] && [ -n "$(ls -A  $dir)" ]   # If true, dir isn't empty.

... but experimenting:

2 /media/sdb 0 $ [ /media/sdb/3/* ] && echo file found

2 /media/sdb 0 $ [ /media/sdb/2/* ] && echo file found
file found

... correct result. I does have a certain logic to it.  If there's no expansion then the test fails.  Dare I use it or is this bound to crash and burn somehow or other?  Anyway I can't believe a call to 'ls' is really needed.






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