bug-bash
[Top][All Lists]
Advanced

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

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


From: linda W
Subject: Bug report: extended pattern match bug (or "feature" [sic] / inconsistency)
Date: Wed, 24 Mar 2004 19:35:39 -0800
User-agent: Mozilla Thunderbird 0.5 (Windows/20040207)

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"
   + echo '3ddiag-+([-0-9.a-z])i586.rpm'
   3ddiag-+([-0-9.a-z])i586.rpm

There is a simple workaround:

   cur=$(echo $a-+([-0-9.a-z])$b)
   ++ echo 3ddiag-0.703-176.i586.rpm
   + cur=3ddiag-0.703-176.i586.rpm
   # echo "$cur"
   + echo 3ddiag-0.703-176.i586.rpm
   3ddiag-0.703-176.i586.rpm

I may be wrong and not understand some subtle difference as to why the first
shouldn't work, but it sorta had me pulling out a few hairs before I figured
out what was going on.

So is there some technical reason why this doesn't seem to follow the
principle of "least surprise" or some other rule that overrides things and says
that pattern evaluation isn't done in the rh expression of the assignment?

When responding, please be sure to "Cc" me, as I am not normally on the bash-bug
list (not usually running into very many bugs! :-)).

Thanks,
Linda





reply via email to

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