[TriLUG] bash scripting and regex help

Chris Merrill chris at webperformance.com
Wed Apr 25 11:10:08 EDT 2012


On 4/25/2012 11:01 AM, Robert Dale wrote:
> I got it to work when using the same quotes around the parameters:
> 
> CMD="expr match '${filename}' '${expression}' "
> or
> CMD="expr match \"${filename}\" \"${expression}\""

Hmmm...interesting. Works for me too.

I thought it was strange to be using two different types of quotes, but
it came right from the Advanced Bash Scripting Guide, so I stuck with it:
http://tldp.org/LDP/abs/html/string-manipulation.html#EXPRPAREN

Thanks!!!  I blew about an hour trying to fix that :(

Chris


> 
> 
> On Wed, Apr 25, 2012 at 10:52 AM, Chris Merrill
> <chris at webperformance.com> wrote:
>> I'm trying to script a process and part of it needs to extract a version
>> number from a filename.  I can do this from the command line easily enough...
>> here is a simplified example:
>>
>>> [root at dawn scripts]# expr match "version_5.1.10577.jar" 'version_\(.*\)\.jar'
>>> 5.1.10577
>>
>> The output is exactly what I need. But when I try to do the same thing inside
>> a script, I get nothing.  This is the script:
>>
>> #!/bin/bash
>> #
>> filename=version_5.1.10577.jar
>> expression="version_\(.*\)\.jar"
>> CMD="expr match \"$filename\" '${expression}'"
>> echo $CMD
>> $CMD
>>
>> and this is the output:
>>
>>> [root at dawn scripts]# ./test.sh
>>> expr match "version_5.1.10577.jar" 'version_\(.*\)\.jar'
>>>
>>> [root at dawn scripts]#
>>
>>
>> I've tried a lot of variations, but none of them get me anything that resembles
>> success, so I think I must be missing something fundamental. Can anyone point
>> me in the right direction?
>>
>> TIA!
>> Chris
>>
>>
>> --
>> ------------------------------------------------------------------------ -
>> Chris Merrill                           |  Web Performance, Inc.
>> chris at webperformance.com                |  http://webperformance.com
>> 919-433-1762                            |  919-845-7601
>>
>> Web Performance: Website Load Testing Software & Services
>> ------------------------------------------------------------------------ -
>> --
>> This message was sent to: Robert Dale <robdale at gmail.com>
>> To unsubscribe, send a blank message to trilug-leave at trilug.org from that address.
>> TriLUG mailing list : http://www.trilug.org/mailman/listinfo/trilug
>> Unsubscribe or edit options on the web  : http://www.trilug.org/mailman/options/trilug/robdale%40gmail.com
>> TriLUG FAQ          : http://www.trilug.org/wiki/Frequently_Asked_Questions
> 
> 
> 


-- 
------------------------------------------------------------------------ -
Chris Merrill                           |  Web Performance, Inc.
chris at webperformance.com                |  http://webperformance.com
919-433-1762                            |  919-845-7601

Web Performance: Website Load Testing Software & Services
------------------------------------------------------------------------ -



More information about the TriLUG mailing list