[TriLUG] bash scripting and regex help

Robert Dale robdale at gmail.com
Wed Apr 25 11:01:34 EDT 2012


I got it to work when using the same quotes around the parameters:

CMD="expr match '${filename}' '${expression}' "
or
CMD="expr match \"${filename}\" \"${expression}\""



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



-- 
Robert Dale



More information about the TriLUG mailing list