This is because the empty $var extension is removed before test sees it. In fact, you run test -f and therefore there is only one arg test argument, namely -f . According to POSIX, one argument of type -f is true because it is not empty.
From the POSIX test specification (1) :
1 argument: Exit true (0) if `$1` is not null; otherwise, exit false.
A file with an empty file name is never tested. Now with explicit test -f "" there are two arguments, and -f recognized as the operator for "checking the existence of the path argument".
source share