Determine if file exists in a Bourne/bash shell script

Contributor Icon Contributed by Rex Date Icon October 20, 2003  
Tag Icon Tagged: Bourne shell scripting


if [ -f testfile ]
then
echo testfile exists!
fi

Previous recipe | Next recipe |
 
  • DaVince
    Just what I needed, thanks.
  • anonymous
    if [ -f testfile ];
    then
    echo Blablabla
    fi
  • James
    total crap, it doesn't actually test if the file is there or not, it just tests if the command line argument is there. There's a giant f*cking differences.
  • Adam
    I don't think you're using it quite right Young Padawan
  • ayw
    if [ -e testfile ]; tests whether a file exists.

    if [ -f testfile ]; only tests whether file is a regular file
  • David
    No. From the man page: " -f filename
    True if filename exists and is a regular file.""
  • Shouldn't that one have some brackets or something?
  • Joeblackspirit
    Perfect and simple!!
blog comments powered by Disqus