[linux-help] Re: Quick BASH/Perl Question
[Top] [All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index] [Thread Index]
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
|
|