双方括号在bash的含义 [英] Meaning of double square brackets in bash
问题描述
在凯尔 - 勃兰特回答这个 的问题在 [[]]
构造被描述为一个bash的内置测试命令。以下示出作为一个例子。
At this question in the answer from Kyle Brandt the [[ ]]
construct is described as a "bash built-in test command". The following is shown as an example.
if [[ ( $a -gt 2 ) && ( $a -lt 5 ) ]]; then ...
为什么双方括号,从字面上 [[]]
,有必要吗?
推荐答案
[[是一个更通用的版本的[在bash。
[[ is a much more versatile version of [ in bash.
例如,使用[[...]]测试结构,而不是[...]可以美元脚本p $ pvent许多逻辑错误。例如,和放大器;&放;, ||,&LT,和>运营商[[]]测试内的工作,尽管内的[]构造给了一个错误
For example, Using the [[ ... ]] test construct, rather than [ ... ] can prevent many logic errors in scripts. For example, the &&, ||, <, and > operators work within a [[ ]] test, despite giving an error within a [ ] construct.
此外,它们的实现是不同的。
also, their implementations are different
-bash-3.2$ type [
[ is a shell builtin
-bash-3.2$ type [[
[[ is a shell keyword
这里请参阅了一个很好的解释
Refer here for a good explanation
这篇关于双方括号在bash的含义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!