test -h 和 test -L 之间的区别
ksh shell 中的 test -L filename
和 test -h filename
有什么区别。从手册页来看,两者都用于识别符号链接,但我想知道确切的区别。
这是手册页中的描述。
-h file True if file exists and is a sym-
bolic link.
-L file True if file exists and is a sym-
bolic link.
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
作者对未来的希望之外,这两个选项的处理方式完全相同:
文件
bltins/test.c
中的ksh93
源代码表明,除了 我的结论是它们的行为完全相同,但-h
是一个遗留选项,可能有一天会消失:-)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 :-)看来它们的存在都是出于遗留原因,以便在不同版本的 Unix 之间兼容。您应该能够使用其中任何一个,因为它们执行完全相同的操作,但请注意,如果您运行的系统不符合最新标准,则可能会缺少其中一个。
这两种形式都存在于单一 Unix 规范版本 3/POSIX 2004 中,没有任何警告:
根据 Mac OS X 上的
test(1)
手册页和 FreeBSD(请注意,此警告可能已过时;它 1996 年首次出现在 NetBSD):显然,某些版本的 Solaris
test
仅支持-h
,并且(早在 2003 年)出于兼容性原因,某些软件已切换为-h
,因此-h
实际上可能是你最好的选择。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.没有什么区别,它们完全一样。它们的存在可能是为了统一 POSIX 之前的不同测试实现。
There is no difference, they are exactly the same. They probably exist to unify different test implementations pre-POSIX.
Fedora 的手册页显示
Fedora's man page says