[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: |
Thu, 25 Mar 2004 14:06:44 -0800 |
User-agent: |
Mozilla Thunderbird 0.5 (Windows/20040207) |
Chet Ramey wrote:
I have a file in a directory:
3ddiag-0.703-176.i586.rpm
I am attempting to set a variable to the name of this file while not
matching other varients of the name.
I decided to use the pattern (correct or not):
$a-+([-0-9.a-z])$b)
"a" and "b" are set:
a=3ddiag
b=i586.rpm
So to set a variable "cur" (indicating current version in current
directory), I used:
cur=$a-+([-0-9.a-z])$b
However, in the above context, the regular expression for the path is
not evaluated.
What I get is:
echo "$cur"
Make sure you have the `extglob' option set
---
If I did not have the "extglob" option set, then the 2nd expansion
cur=$(echo $a-+([-0-9.a-z])$b) wouldn't
have worked (i.e. it is set).
and unquote the expansion.
The expansion is unquoted:
cur=$a-+([-0-9.a-z])$b
Quotes inhibit pathname expansion.
I know, but to see the "real" value inside "$cur", I have to use quotes,
otherwise, I get a 2nd expansion when I use "echo" to print out the value of $cur.
That wouldn't show the contents of cur but would show the contents after having
been
_re_-evaluated_. The problem I'm trying to show is that the value stored in
"cur" is
not expanded if I use "straight assignment", but is evaluated if I pre-evaluate it as the
output of a subprocess. But a subprocess isn't required to evaluate the expression, since
typing the express "naked" (not in an assignment), does evalute it correctly the first time:
a=3ddiag
b=i586.rpm
echo $a-+([-0-9.a-z])$b
3ddiag-0.703-176.i586.rpm ## expanded correctly on first
try
I'll show you a different example that uses no quotes but still shows the
difference:
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
export cur=$(echo $a-+([-0-9.a-z])$b)
printenv|grep cur
cur=3ddiag-0.703-176.i586.rpm ## value in cur is stored in
expanded form
---
sorry for curtness email, gotta run/ late4 appt.
-linda