bash 字符串相等
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3265803/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
bash string equality
提问by brianegge
In bash
, what's the difference, if any, between the equal and double equal test operators?
在 中bash
,相等和双相等测试运算符之间有什么区别(如果有)?
[[ "a" = "a" ]] && echo equal || echo not-equal
[[ "a" == "a" ]] && echo equal || echo not-equal
[[ "a" = "b" ]] && echo equal || echo not-equal
[[ "a" == "b" ]] && echo equal || echo not-equal
results in:
结果是:
equal
equal
not-equal
not-equal
采纳答案by schnaader
There's no difference, ==
is a synonym for =
(for the C/C++ people, I assume). See here, for example.
没有区别,==
是=
(对于 C/C++ 人,我假设)的同义词。例如,请参见此处。
You could double-check just to be reallysure or just for your interest by looking at the bash source code, should be somewhere in the parsing code there, but I couldn't find it straightaway.
你可以仔细检查只是要真正确保或只是通过看你的兴趣bash的源代码,应该是某处解析代码,但我不能直截了当找到它。