|
| From: | Linda Walsh |
| Subject: | Re: capturing sub-expressions? |
| Date: | Tue, 29 Jan 2008 17:41:35 -0800 |
| User-agent: | Thunderbird 2.0.0.9 (Windows/20071031) |
Paul Jarc wrote:
Linda Walsh <bash@tlinx.org> wrote:In my copy of the man pages, Pattern matching is indented an extra level making it look like it's under Pathname Expansion and only applies there....Pattern matching applies primarily to pathname expansion; other uses explicitly refer to its use there: ${parameter/pattern/string} The pattern is expanded to produce a pattern just as in pathname expansion. Parameter is expanded and the longest match of pattern against its value is replaced with string. [...]I wanted to leave "myswitch2" as the only thing left in $p;p=" $p " p=${p/* myswitch2 */myswitch} p=${p/ */}
-----
I simplified my example a bit too much...
p="-e -p 60 -x"
---
That's why I wanted the capture -- to pick out the 60 -- where 60 represents
a positive integer. The space between the -p and the number is optional.
I can get at the 60 using multiple "nibbles" off the front and end of
the string, but no [easy] way I can think of to get at it directly.
I figured with "capture", I could substitute it in as the replacement
string. with nibbling, it makes for convoluted code that doesn't
feel "robust" (and I can easily come up with specific (though unlikely
to be used in practice) examples to cause failure).
Harder targets included more "switches" (-b, -v and -t which all take
arguments which may or may not be separated from the switch by a space.
Switches (and their values) are space separated. I'm not worrying
about supporting embedded spaces in filenames.
p="-e -p60 -b 1m -v string -tfile"
Switch -b has some decimal value with an optional suffix in the set
"kmgtpesb". But the above target isn't really needed AFAIK in the near
future.
| [Prev in Thread] | Current Thread | [Next in Thread] |