1
TerrenceSun 2015-06-16 10:19:25 +08:00
就像你说的[test_condition],中的"["是一个命令,而不是语法中的括号。如果是括号就一定要成对出现了。
之所以要有"]",我认为是为了语义上符合逻辑。 |
2
lerosua 2015-06-16 11:21:30 +08:00
我认为[是个命令,那]可以是参数,形成闭合。
如果]是命令,那没法搞,因为没有开头是 ] xxx 的语法传统。它的参数按照传统的命令行参数传递顺利,传不进去。 |
3
SoloCompany 2015-06-16 14:05:23 +08:00
2 楼是正确的
[ a ] 就是执行命令 [ 带两个参数 a 和 ] [ 命令要求最后一个参数必须是 ] 否则报错 它最终等价于 test a [ 和 test 是完全一样的命令,除了对最后一个参数的解释的差异 |
4
webjin OP 下面是我man test 得到的解说,但是我英语不才,翻译看不懂专业术语
===================================================== Except for -h and -L, all FILE-related tests dereference symbolic links. Beware that parentheses need to be escaped (e.g., by backslashes) for shells. INTEGER may also be -l STRING, which evaluates to the length of STRING. NOTE: [ honors the --help and --version options, but test does not. test treats each of those as it treats any other nonempty STRING. NOTE: your shell may have its own version of test and/or [, which usually supersedes the version described here. Please refer to your shell’s documentation for details about the options it supports. |