为什么周围添加的bash比较操作空间改变的结果? [英] Why does adding spaces around bash comparison operator change the result?

查看:102
本文介绍了为什么周围添加的bash比较操作空间改变的结果?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人能解释一下周围为什么空间== 更改比较结果呢?以下内容:

Could someone explain why spaces around == change the comparison result? The following:

if [[ 1 == 2 ]] ; then echo ok ; fi

打印什么,而

if [[ 1==2 ]] ; then echo ok ; fi

打印确定

推荐答案

1 == 2是一个4个字符的字符串,而不是前pression涉及 == 运营商。非空字符串始终为true在条件前pression的背景下 [...] 。空白是围绕强制性== 运营商。

"1==2" is a single 4-character string, not an expression involving the == operator. Non-empty strings always evaluate to true in the context of the conditional expression [[ ... ]]. Whitespace is mandatory around the == operator.

庆典一切,的内容[...]] 只是一个白 - 参数用空格分开的列表。在庆典语法并不知道如何解析条件前pressions,但它知道如何跨preT喜欢的3个参数列表 1 == 2 的背景下的 [...] 复合命令。

Like everything else in bash, the contents of [[ ... ]] are simply a white-space-separated list of arguments. The bash grammar doesn't know how to parse conditional expressions, but it does know how to interpret a list of 3 arguments like 1, ==, and 2 in the context of the [[ ... ]] compound command.

这篇关于为什么周围添加的bash比较操作空间改变的结果?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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