Complete.Org: Mailing Lists: Archives: linux-help: January 2001:
[linux-help] Re: Quick BASH/Perl Question
Home

[linux-help] Re: Quick BASH/Perl Question

[Top] [All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
To: linux-help@xxxxxxxxx
Subject: [linux-help] Re: Quick BASH/Perl Question
From: Tom Hull <thull@xxxxxxxxxxx>
Date: Thu, 11 Jan 2001 16:03:38 -0600
Reply-to: linux-help@xxxxxxxxx

Jeff Vian wrote:
> 
> Using John's answer, the following will easily work
> 
> for fname in `ls *.log`
> do
>     if [ -f ${fname} ]; then
>         echo "${fname} exists"
>     fi
> done

ls(1) will only print the names of files which exist, so the
test -f is not necessary. fname will not be set if there are
no *.log files.

however, ls will print an ugly error message to stderr, so

  2>/dev/null

may be advised. also, if *.log returns a directory, ls will
print out a list of its contents, which is not what you want.
ergo:

  for fname in `ls -d *.log 2>/dev/null`
  do
    echo "${fname} exists"
  done

-- 
/*
 *  Tom Hull * thull at kscable.com * http://www.ocston.org/~thull/
 */

-- This is the linux-help@xxxxxxxxx list.  To unsubscribe,
visit http://tmp2.complete.org/cgi-bin/listargate-aclug.cgi


[Prev in Thread] Current Thread [Next in Thread]