Mailinglist Archive: opensuse (888 mails)

< Previous Next >
[opensuse] Re: bash test for empty dir
  • From: Joachim Schrod <jschrod@xxxxxxx>
  • Date: Fri, 21 Jan 2011 13:54:50 +0100
  • Message-id: <ihbvmq$7n3$>
David Haller wrote:
On Thu, 20 Jan 2011, David C. Rankin wrote:
I stumbled across a neat use of ls -A for testing for an empty dir that
thought I would pass on:


if [[ $(ls -A ${1}) ]]; then

And I'd prefer the more readable and portable

if test -n "$(ls -A "$1")"; then

David, I know that you know it; but for the sake of the archives:

Quotes are wrong, that should be "$(ls -A \"$1\")".
If the directory name starts with an hyphen, it'll get an error,
too. So better make it "$(ls -A -- \"$1\")".


Joachim Schrod Email: jschrod@xxxxxxx
Roedermark, Germany

To unsubscribe, e-mail: opensuse+unsubscribe@xxxxxxxxxxxx
For additional commands, e-mail: opensuse+help@xxxxxxxxxxxx

< Previous Next >
Follow Ups