我在回答另一个问题时注意到test
,[
它们是不同的二进制文件,但[
联机帮助页上拉了test
。除了结尾的要求外]
,有什么区别吗?如果不是,为什么它们将二进制文件分开而不是被符号链接?(它们也是bash
内置的,bash
也没有区别。)
该源代码解释的差异为如何处理的--help
选项。
/* Recognize --help or --version, but only when invoked in the "[" form, when the last argument is not "]". Use direct parsing, rather than parse_long_options, to avoid accepting abbreviations. POSIX allows "[ --help" and "[ --version" to have the usual GNU behavior, but it requires "test --help" and "test --version" to exit silently with status 0. */
示范
$ /usr/bin/test --help
$
$ /usr/bin/[ --help
Usage: test EXPRESSION
or: test
or: [ EXPRESSION ]
or: [ ]
or: [ OPTION
Exit with the status determined by EXPRESSION.
[...]
如您所说bash
,在内置版本中,唯一的不同是最后[
需要]
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句