What is the difference between test -L filename
and test -h filename
in ksh shell. From the man page, both were used to identify a symbolic link, but I want to know the exact difference.
Here is the description from the man page.
-h file True if file exists and is a sym-
bolic link.
-L file True if file exists and is a sym-
bolic link.
There is no difference, they are exactly the same. They probably exist to unify different test implementations pre-POSIX.
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:
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):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.The source code for
ksh93
, in filebltins/test.c
, shows that these two options are treated exactly the same, except for the author's hopes for the future:From this I conclude that they behave exactly the same, but that
-h
is a legacy option and may one day disappear :-)Fedora's man page says