bug-bash
[Top][All Lists]
Advanced

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

Re: capturing sub-expressions?


From: Bernd Eggink
Subject: Re: capturing sub-expressions?
Date: Mon, 28 Jan 2008 17:16:22 +0100
User-agent: Thunderbird 2.0.0.9 (X11/20071031)

Linda Walsh schrieb:
I was wondering -- in the bash substitute commands ${..%%|##|//} etc,
is there a way to "capture" a subexpression, so that I can
use the subexpression in the replacement string so I can
end up 'only' with the the subexpression?

If the full expression was in a shellvar "Options", I thought about
using something like:
    ${Option//!(expr)}
which I hoped would have "!(expr) match anything but my desired
expression, and the double "/" would say allow it to match multiple
times, but it appears the "!()" construct is limited to pathname
expansion?  Presuming that is true (limited to pathname expansion),
is there anyway to do it on Shell vars?

I keep confusing the path-matching regular expressions with
string-matching expressions and keep getting disappointed when I'm
re-reminded of the limitation...:-(

There should be no difference between path-matching and string-matching expressions. Normally even nested extended patterns work with string matching. But, in fact, !(...) appears to not work like one would expect. The only case that looked correct to me is the trivial one ${x//!(*)}, which leaves $x unchanged.

I'm not sure whether this is a bug or I (we) miss something. Interestingly, ksh behaves the same way. Can anybody clarify this?

Regards,
Bernd

--
Bernd Eggink
monoped@sudrala.de
http://sudrala.de




reply via email to

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