Quantcast
Channel: bash [[ = ]] behaviour - Unix & Linux Stack Exchange
Viewing all articles
Browse latest Browse all 2

bash [[ = ]] behaviour

$
0
0

man bash:

[[ expression ]]
[...] Expressions are composed of the primaries described below under CONDITIONAL EXPRESSIONS. Word splitting and pathname expansion are not performed on the words between the [[ and ]];
[...] When the == and != operators are used, the string to the right of the operator is considered a pattern and matched according to the rules described below under Pattern Matching.

In the whole section the case of a single = is not mentioned.

CONDITIONAL EXPRESSIONS
[...]
string1 == string2
string1 = string2
True if the strings are equal. = should be used with the test command for POSIX conformance.

From this description I would expect that

[[ a = $cmpstring ]]

checks for equal strings and

[[ a == $cmpstring ]]

checks for a pattern match. But that is not the case:

> [[ a == ? ]]; echo $?
0
> [[ a = ? ]]; echo $?
0
> [[ a == "?" ]]; echo $?
1

Do I misunderstand something or has the bash man page just forgotten to mention =?


Viewing all articles
Browse latest Browse all 2

Latest Images

Trending Articles



Latest Images