双方括号在bash的含义 [英] Meaning of double square brackets in bash

查看:137
本文介绍了双方括号在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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆