$ kpsewhich --expand-var=\$NONEXISTENTVAR; echo $? Internally, variable.c:kpse_var_expand, which is what's being called, does not distinguish between unset and set to empty. If you want to distinguish, use -var-value=NONESUCH. Exit status is 1 if not set. Quoting is simpler too :).