I'm curious why is -e is what I usually see for file existence checking and not -f?
I'd say it's probably because -f can be a little too restrictive:
$ perl -le 'print -f "/dev/null" ? "IS" : "is NOT", " a file"' is NOT a file
but it's also true that sometimes -e gets overused when a more restrictive check would have been better, for example at least checking ! -d.
Update: Just to clarify what I meant with the above example: If a user is supposed to supply a filename to a program, then in a lot of cases the program shouldn't reject /dev/null and just work with it as if it was a regular file. Of course there might be cases where a program would want to accept only regular files - but then again, -f also returns true if what's being tested is a symbolic link to a file, so one would have to check for that specially too.
In reply to Re^3: Check if file exists
by haukex
in thread Check if file exists
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |