zsh-users
 help / color / mirror / code / Atom feed
From: Ray Andrews <rayandrews@eastlink.ca>
To: Zsh Users <zsh-users@zsh.org>
Subject: quick and dirty test for empty directory
Date: Wed, 16 Nov 2022 08:17:38 -0800	[thread overview]
Message-ID: <620799bc-8224-7cf3-b1c5-2ae5467f0a98@eastlink.ca> (raw)

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.




             reply	other threads:[~2022-11-16 16:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-16 16:17 Ray Andrews [this message]
2022-11-16 16:23 ` Roman Perepelitsa
2022-11-16 18:00   ` Ray Andrews

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=620799bc-8224-7cf3-b1c5-2ae5467f0a98@eastlink.ca \
    --to=rayandrews@eastlink.ca \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).