There are two switches for the if condition which check for a file: -e and -f.
What is the difference between those two?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
See: http://tldp.org/LDP/Bash-Beginners-Guide/html/sect_07_01.html
I believe those aren’t “if switches”, rather “test switches” (because you have to use them inside [] brackets.
But the difference is:
[ -e FILE ]True if FILE exists.This will return true for both
/etc/hostsand/dev/nulland for directories.[ -f FILE ]True if FILE exists and is a regular file.This will return true for
/etc/hostsand false for/dev/null(because it is not a regular file), and false for/devsince it is a directory.