Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
->[[ "abc~" == *~ ]]; echo $?; [[ *~ == "abc~" ]]; echo $? 0 1
在上面的片段中,为什么比较顺序似乎会影响真值?
模式匹配仅在==. 第二个示例按*~字面意思计算字符串。
==
*~
这就是为什么在双括号中的表达式的右侧需要引用,而左侧不需要引用的原因。
[[ $a == "$b" ]] # Right [[ "$a" == $b ]] # Wrong