bash if file exists
Eric Chadbourne
EChadbourne at targetsite.com
Fri Apr 4 12:17:56 EDT 2008
> Ben Eisenbraun wrote:
> > On Thu, Apr 03, 2008 at 06:55:36PM -0400, Derek Martin wrote:
> >> Which can be further simplified to:
> >>
> >> if ls *.zip >/dev/null 2>&1; then
> >
> > That's probably more elegant on some level than my $?.
> Derek's test
> > of the ls exit status embedded in the if statement jogged my memory
> > for another
> > method:
> >
> > ls *.zip > /dev/null 2>&1 && echo 'zips!' || echo 'zippo!'
> >
> > There ends up being a tradeoff between brevity and
> legibility at some
> > point, but I don't think we've hit it yet. Anyone got a
> shorter one?
> >
> > :-)
> >
> > -b
>
> Hey, I like that! Much cleaner than my "find" approach.
>
> I didn't realize that ls returns a non-zero return code when
> nothing found. Neat trick!
>
> DR
Wow, excellent responses to this "simple" question!
- Eric C
--
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.
More information about the Discuss
mailing list