Re: [LIP] want to test presence of file

Sandip Bhattacharya <[email protected]>
Newsgroups gmane.user-groups.linux.india.programmers
Organization Puroga Technologies Pvt. Ltd.
Message-ID <[email protected]>
On Fri, 2005-02-11 at 14:32 +0530, Sandip Bhattacharya wrote:
> On Fri, 2005-02-11 at 14:05 +0530, Manish Satwani wrote:
> > Hi All, 
> > I am doing shell programming 
> > I am making a command line tool which accept a argument  that is a file name....
> > I want to check whether the file present or not (How can I check in
> > Shell programming?)
> > 
> 
> Use the -f test.
> 
> [ -f /usr/share/dict/words ] && echo "'dict words' present"
> [ -f /usr/share/dict/words2 ] || echo "'dict words2' not present"
> 

>From "man bash":

-----------------------------------
CONDITIONAL EXPRESSIONS

       -e file
              True if file exists.
       -f file
              True if file exists and is a regular file.
-----------------------------------

So use -e as Chandrashekhar Babu suggested if you just want to test for
existence. Use -f if you also want to test if the file is not a special
file.

- Sandip


--
Sandip Bhattacharya    *    Puroga Technologies   *     sandip-/[email protected]
Work: http://www.puroga.com   *    Home/Blog: http://www.sandipb.net/blog

PGP/GPG Signature: 51A4 6C57 4BC6 8C82 6A65 AE78 B1A1 2280 A129 0FF3




-------------------------------------------------------
SF email is sponsored by - The IT Product Guide
Read honest & candid reviews on hundreds of IT Products from real users.
Discover which products truly live up to the hype. Start reading now.
http://ads.osdn.com/?ad_id=6595&alloc_id=14396&op=click
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.