On 9/17/10 6:50 PM, Linda Walsh wrote: > > > Jan Schampera wrote: >> == is the same as =, my suggestion is to NOT touch that. > ===
I'm not going to say too much on this. The behavior as it exists now is very consistent: for both == and =~, any part of the rhs that's quoted is matched as a string. Period. It was a mistake not to do it that way in the first place. Matching is different from word expansion. The word expansions that take place in double-quoted words on the rhs of == and =~ are the same. I really don't understand a lot of Ms. Walsh's argument. I appreciate the effort she's put into this, but none of the examples she presents demonstrate what I think she's trying to prove. > Single quotes do not allow expansion of > variables, double quotes do expansion of variables. I.e. > > A. t='one two three' > a='two' > 1) if [[ $t == 'one $a three']]; then echo 'no match expected'; fi > 2) if [[ $t == "one $a three"]]; then echo 'Matches'; fi > 3) if [[ $t == one\ $a\ three ]]; then echo 'Matches'; fi > > So for =/==, double quotes allows *grouping* and is equivalent to 3. > But for the =~, it is broken: > > B. > t='one two three' > a='t..' > 1) if [[ $t =~ 'one $a three' ]]; then echo 'no match expected'; fi > 2) if [[ $t =~ "one $a three" ]]; then echo 'SHOULD Match'; else echo 'BUG, > double quotes disable match'; fi > 3) if [[ $t =~ one\ $a\ three ]]; then echo 'Matches'; fi You realize these two cases are not equivalent, right? Why would you expect A2 and B2 to be treated the same when one's a string and one's a pattern? > > -- but even more of the badness, single quotes disable matching entirely: > 4) if [[ $t =~ one\ t..\ three ]]; then echo 'Matches'; fi > 5) if [[ $t =~ 'one t.. three' ]]; then echo 'SHOULD Match'; else echo > 'BUG, double quotes disable match'; fi More precisely, quoted characters are matched as strings, with any special matching significance removed. > Or another disparity: C. > t='one two three' > c='one two three' > 1) if [[ $t == $a ]]; then echo 'Matches'; fi > 2) if [[ $t == "$a" ]]; then echo 'Matches'; fi > So, the expressions match whether or not $a is in double quotes or not Of course they do. They're the same string (I'm assuming that the assignment to `c' was a typo). There's no pattern matching happening at all. > (single quotes would not match, as the $a would be taken literally). > > But, with the operator that says 'take right hand expression as 'RE', do we > get consistent behavior?: > t='one two three' > a='one t.. three' > 3) if [[ $t =~ $a ]]; then echo 'Matches'; fi > 4) if [[ $t =~ "$a" ]]; then echo 'SHOULD Match'; else echo 'BUG, double > quotes disable match'; fi > Now, double quotes Don't behave consistently -- AGAIN.... Again, the examples are not equivalent. Did you do this deliberately? You're not helping your argument any by using examples that can at best be considered disingenuous and at worst deliberately misleading. -- ``The lyf so short, the craft so long to lerne.'' - Chaucer ``Ars longa, vita brevis'' - Hippocrates Chet Ramey, ITS, CWRU c...@case.edu http://cnswww.cns.cwru.edu/~chet/