*BSD News Article 24550


Return to BSD News archive

Path: sserve!newshost.anu.edu.au!munnari.oz.au!news.Hawaii.Edu!ames!agate!usenet.ins.cwru.edu!cleveland.Freenet.Edu!bx970
From: bx970@cleveland.Freenet.Edu (Donna A. Lilly)
Newsgroups: comp.unix.bsd
Subject: test if file exists in script
Date: 30 Nov 1993 07:59:45 GMT
Organization: Case Western Reserve University, Cleveland, OH
Lines: 22
Message-ID: <2deuhi$7lh@usenet.INS.CWRU.Edu>
Reply-To: bx970@po.cwru.edu (Donna Lilly)
NNTP-Posting-Host: nextsun.ins.cwru.edu

What is the best way to test in a shell script (e.g. c shell or t shell if
possible) whether a filename already exists?  Given a variable file, I
could use:

% if (`find . -name '$file' -print | wc -c` != 0) then
    .....

But I know there is a much better way.  I also didn't have much success
with use of 

% if (`test -s $file`) then

also I tried the above without the backquotes, still didn't get any result
from the test command...

Someone please tell!

Thanks for your help!

-- 
        Donna Lilly
        Cleveland, OH