On 8/1/2010 8:11 PM, Chris F.A. Johnson wrote: > On Sun, 1 Aug 2010, Linda Walsh wrote: > >> I have: >> >> w="/home/law/bin/package: line 5: type: xx: not found" >> >> The =~ operator is suppose to use the RH Expr as a ext.-regex. >> >> So why doesn't this match and print "not found"? >> >> if [[ $w =~ ".*not found.*" ]]; then echo "not found"; fi >> >> It prints nothing. Seems like such a basic concept. Sorry, this newbie >> needs help on such trivial matters. :-( > > When quoted, the right-hand argument is matched as a string, not an > expression. >
So that's how it is... Aren't single quotes reserved for making things literal, while double quotes are used for grouping, yet interpreting what is between them (expansions and such). Is there a reason "RH =~" was made inconsistent regarding this practice? I might note: the man page makes no reference to such heinous behavior, leading one me to think I'd use single quotes if I didn't want the contents to be 'active' Though to tell the truth. Technically, it says: An additional binary operator, =~, is available, with the same precedence as == and !=. When it is used, the string to the right of the operator is considered an extended regular expres- sion and matched accordingly (as in regex(3)). I don't see anything about quotes making the =~ operator behave like the == operator. I'm not sure I see the usefulness in that. If there is, then is it necessary to reserving both single and double quotes to make "=~" behave like "=="? Therefore: RFE: Please make double quotes a grouping operator to group multiple words (as in separated by spaces) together -- even if it is on the RH of =~. Let single quotes be the 'do not interpret this' signifier. Otherwise there's no nice way to group together patterns that have spaces in them. Inserting '\' before every space isn't my idea of nice: Ick! p.s. -- why do you want to have =~ behave like ==? I.e. why these special cases to deactivate regex? Isn't the whole point of =~ to use the RH as an regex? Why have syntax to disable it? I.E -- please consider another possibility: Using double quotes would first do a variable substitution pass, while using single quotes would not -- but use the literal string as a regex. Why throw away useful functionality of quotes with a new operator?