help-bash
[Top][All Lists]
Advanced

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

Re: [Help-bash] How to extract matching suffix pattern in bash?


From: Chet Ramey
Subject: Re: [Help-bash] How to extract matching suffix pattern in bash?
Date: Thu, 14 Mar 2013 10:07:30 -0400

> On 03/13/2013 08:04 PM, Chet Ramey wrote:
> > On 3/13/13 6:21 PM, Peng Yu wrote:
> >> Hi,
> >>
> >> ${parameter%word} remove matching suffix pattern. I need something
> >> extract only the matching suffix which is to be not available
> >> according to bash manual. Do I miss anything?
> > 
> > This is totally untested, but should be fairly self-explanatory, and is
> > portable to any Posix shell:
> > 
> > suffix_pattern=whatever
> > prefix=${string%$suffix_pattern}
> > suffix=${string##$prefix}
> 
> Except that it isn't robust if pattern contains globs:

Quote to taste.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
                 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRU    address@hidden    http://cnswww.cns.cwru.edu/~chet/



reply via email to

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