Kev*_*vin 15 linux command-line utilities coreutils test
我在回答另一个问题时注意到test和[是不同的二进制文件,但[联机帮助页会显示test's. 除了对结局的要求],还有什么区别吗?如果不是,为什么它们分开二进制文件而不是符号链接?(它们也是bash内置bash函数,也没有区别。)
该源代码解释的差异为如何处理的--help选项。
Run Code Online (Sandbox Code Playgroud)/* 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.
[...]
Run Code Online (Sandbox Code Playgroud)
在bash内置版本中,唯一的区别是最后[需要],如您所说。
通常,它们是具有硬链接的相同二进制文件。根据不同的外壳,内部实现可用于test和[测试,而不是二进制。这在进程生成方面更有效,并且可能提供与二进制程序不同的选项test。
除了调用格式的不同外,它们都提供相同的功能。
| 归档时间: |
|
| 查看次数: |
715 次 |
| 最近记录: |