[Top][All Lists]

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

Re: Question about patterns

From: Roman Rakus
Subject: Re: Question about patterns
Date: Thu, 23 Jun 2011 17:03:22 +0200
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv: Gecko/20110307 Fedora/3.1.9-0.39.b3pre.fc14 Lightning/1.0b3pre Thunderbird/3.1.9

On 06/23/2011 04:56 PM, Roman Rakus wrote:
On 06/23/2011 03:59 PM, Steven W. Orr wrote:
I may be wrong, but I think there's a way to do what I want without using a regex.

I have a file called foo-1.2-3.tar.gz
I need to set a variable equal to

Is there a way to do this without parsing my brains out? I am facile with the variable operations like # ## % %% and /, but what I really want to do is to say something like


where the \1 is some sort of thing that I can use to refer to a backref. Does this exist in bash or do I just do it with a regex?

TIA :-)

Pattern matching in [[ expression ]] and BASH_REMATCH variable are your friends (using regex). Anyway, it's possible to do it with parameter expansions. In two steps or so...

$ ./test.sh foo-1.2-3.tar.gz

$ cat test.sh
echo ${1%-*}-i386-x86_64-${1##*-}


reply via email to

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