Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
quick and dirty test for empty directory
- X-seq: zsh-users 28395
- From: Ray Andrews <rayandrews@xxxxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: quick and dirty test for empty directory
- Date: Wed, 16 Nov 2022 08:17:38 -0800
- Archived-at: <https://zsh.org/users/28395>
- List-id: <zsh-users.zsh.org>
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