It appears that they both exist for legacy reasons, to be compatible between different versions of Unix. You should be able to use either one, as they do the exact same thing, but be aware that if the system you are running on is not compliant with the latest standards, it may be missing one or the other.
Both forms are present in the Single Unix Specification version 3/POSIX 2004, with no caveats:
-h pathname
True if pathname resolves to a file that exists and is a symbolic link. False if pathname cannot be resolved, or
if pathname resolves to a file that exists but is not a symbolic link. If the final component of pathname is a
symlink, that symlink is not followed.
-L pathname
True if pathname resolves to a file that exists and is a symbolic link. False if pathname cannot be resolved, or
if pathname resolves to a file that exists but is not a symbolic link. If the final component of pathname is a
symlink, that symlink is not followed.
According to the test(1)
man page on Mac OS X and FreeBSD (note that this warning may be outdated; it first appeared in NetBSD in 1996):
-h file True if file exists and is a symbolic link. This operator
is retained for compatibility with previous versions of
this program. Do not rely on its existence; use -L instead.
And apparently, some versions of Solaris test
only support -h
, and (back in 2003) some software has switched to -h
for compatibility reasons, so -h
may actually be your best bet.