testing if a file is present

Geoff Clare gwc at root.co.uk
Wed Nov 28 00:55:50 AEST 1990


In <1990Nov21.155149.3505 at informix.com> dberg at informix.com (David I. Berg) writes:

>if (-f filename) will return true if the file exists, false if not.

Wrong.  It will return true if the file exists AND IS A PLAIN FILE.
To test for existence only use -e.

This is one place where csh has an advantage over Bourne shell.  There is
no equivalent way with the Bourne shell "test" command to test for existence
without also testing for a specific file type or access mode.  OK, so you
can do it with

	test -f file -o -d file -o -c file -o -b file -o -p file

but I don't count that as "equivalent"!

-- 
Geoff Clare <gwc at root.co.uk>  (Dumb American mailers: ...!uunet!root.co.uk!gwc)
UniSoft Limited, Hayne Street, London EC1A 9HH, England.   Tel: +44-71-315-6600



More information about the Comp.unix.shell mailing list