bash: validating a file (existence, type...)

This is a wiki page. Be bold and improve it!

If you have any questions about the content on this page, don't hesitate to open a new ticket and we'll do our best to assist you.

How to validate a file?

#!/bin/bash
FILE=$1

if [ -f $FILE ];
then
   echo "The file $FILE exists."
fi

# For a directory, use -d:

if [ ! -d $FILE];
then
    echo "The file $FILE is not a directory."
fi

For more information, see section "6.4 Bash Conditional Expressions" of the bash documentation:
http://www.gnu.org/software/bash/manual/bash.html#Bash-Conditional-Expre...