bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: RFE: allow double quotes to group multi-words & be treated as 1 arg,


From: Davide Brini
Subject: Re: RFE: allow double quotes to group multi-words & be treated as 1 arg, w/DQ's stripped off -- including RH =~
Date: Wed, 4 Aug 2010 09:27:48 +0100
User-agent: KMail/1.13.3 (Linux/2.6.32-gentoo-r10; KDE/4.4.4; x86_64; ; )

On Wednesday 04 Aug 2010 09:06:16 Linda Walsh wrote:
> 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 "=="?

From the Changelog:

This document details the changes between this version, bash-3.2-alpha,
and the previous version, bash-3.1-release.
...
3.  New Features in Bash
...
f.  Quoting the string argument to the [[ command's  =~ operator now forces
    string matching, as with the other pattern-matching operators.


From the file COMPAT:

33. Bash-3.2 adopts the convention used by other string and pattern matching
    operators for the `[[' compound command, and matches any quoted portion
    of the right-hand-side argument to the =~ operator as a string rather
    than a regular expression.

34. Bash-4.0 allows the behavior in the previous item to be modified using
    the notion of a shell `compatibility level'.



Finally, to set a given compatibility level, one uses 

shopt -s compat31

This is in the man page:

compat31
        If set, bash changes its behavior to that of version 3.1 with respect
        to quoted arguments to the conditional command's =~ operator.

So your example would have worked with "shopt -s compat31".

-- 
D.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]