[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: shell game



Michael Heironimus <mkh01@earthlink.net> wrote:
> 
> There is a way that looks slightly better, but it's still ugly because
> it relies on bash-specific options. Something like this should do it.
> 
> #! /bin/bash
> # Make globs that don't match expand to null string
> shopt -s nullglob
> if [ -n "$(echo /path/to/*.jpg)" ] ; then
>        # Do stuff because .jpg files exist
> fi

Here's how you can do it in a POSIX shell:

set -- /path/to/*.jpg
if [ -e "$1" ]; then
	# Do stuff because .jpg files exist
fi
-- 
Debian GNU/Linux 3.0 is out! ( http://www.debian.org/ )
Email:  Herbert Xu ~{PmV>HI~} <herbert@gondor.apana.org.au>
Home Page: http://gondor.apana.org.au/~herbert/
PGP Key: http://gondor.apana.org.au/~herbert/pubkey.txt



Reply to: