Re: shell game
Drew Cohan wrote:
>Hi,
>
>Using a bash shell script (/bin/sh), I need to know how to check to see
>if certain files exist in a directory, as in, "Are there any jpegs in
>this directory?". I've tried various things (like using -s, -f with
>test and a do/for loop) but nothing seems to work right. The closest I
>can come is
>
>if test `ls /opt/images/*.jpg | wc -l` -gt 0 then ...
>
>Unfortunately, this gives me the error message "ls: /opt/images/*.jpg:
>No such file or directory" when there are no jpegs in /opt/images.
Try
ls *.jpg > /dev/null 2>&1 # tested command--output is
# superfluous
if
[ $? eq 0 ] # did last command succeed?
then echo "yes" # shout hooray
else echo "no" # tears in your beer
fi
--
gt kk5st@sbcglobal.net
It ain't so much what you don't know that gets you in trouble---
it's what you do know that ain't so.--unk
Reply to:
- References:
- shell game
- From: "Drew Cohan" <drewcohan@drewcohan.com>