bug-bash
[Top][All Lists]
Advanced

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

Re: Bug report: extended pattern match bug (or "feature" [sic] /inconsis


From: linda W
Subject: Re: Bug report: extended pattern match bug (or "feature" [sic] /inconsistency)
Date: Fri, 26 Mar 2004 01:07:30 -0800
User-agent: Mozilla Thunderbird 0.5 (Windows/20040207)



Chet Ramey wrote:

The expansion is unquoted:
cur=$a-+([-0-9.a-z])$b

Pathname expansion is not performed on the rhs of assignment
statements, unquoted or not.

Ok...I guess I missed that somewhere. It seems counter-intuitive since variables are expanded.

It's the expansion of that variable that
causes pathname expansion to be performed.

I'll show you a different example that uses no quotes but still shows the difference:

export cur=$a-+([-0-9.a-z])$b

This is not an assignment statement; it's an argument to `export' that
happens to look like an assignment statement, so pathname expansion is
performed.

----
If it supposed to be expanded, then there would be a different bug to be
reported, but it wasn't expanded in my example:

:> export cur=$a-+([-0-9.a-z])$b
:> printenv|grep cur cur=3ddiag-+([-0-9.a-z])i586.rpm ## value in cur is stored in unexpanded form
---

I suspect the "export" keyword doesn't change the fact that the rest of the
statement is still an assignment statement.
You can see the same behavior w/o export, but using "set" to display the unexpanded value of "cur":

#> cur=$a-+([-0-9.a-z])$b
#> set|grep "^cur"
cur='3ddiag-+([-0-9.a-z])i586'

The short example I gave in my reply was intended to demonstrate that:
assignment statements do not cause pathname expansion to be performed
on the rhs; quoting a variable whose value contains a pattern matching
character inhibits pathname expansion; and that pathname expansion is
performed on the results of an unquoted variable expansion.

----
I was trying to inhibit pathame expansion during printout -- in my script,
I had been trying to do somethign along the lines of
# cur=<expression in update dir>
# old=../old/<same expression in  old dir>,
then test for the existance of $old -- but I thought I might have
the possiblity of having spaces in the expression $old expanded to, so I wanted to put quotes around $old in my test: "if [ -e "$old" ]; then blah blah...." As you note, the quotes inhibit pathame expansion, but I had expected pathname expansion to occur
in the rhs of my assignment.
If I did *NOT* want pathname expansion in my rhs, I would have thought to put
quotes around it, like
cur="$a-+([-0-9.a-z])$b"
In my simplistic mind, I sorta thought pathname expansion didn't occur
in quotes, but did occur outside of quotes, thus my surprise when I didn't get pathname
expansion on the simple assignment.

Was there a reason for this design rule? It seems like it would have been more consistent to expand rhs's in assignments, and inhibit expansion by using quotes.

Thanks for the explanation, but it still leaves me a bit puzzled as to what the
thoughts were that were going through the designer's head when this was
implemented....just seems inconsistent.

Thanks for the new "exception to the rule" of pathname expansion happening outside of quotes....have to remember that non-quoting of the right hand expression isn't
subject to normal expression evaluation rules. :-(.

At least it's a known "feature", though, I'm not real convinced it's a
consistent or a positive feature at this point (but I'm open to being
convinced otherwise! :-)).

-linda





reply via email to

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