[TriLUG] bash scripting and regex help
Chris Merrill
chris at webperformance.com
Wed Apr 25 10:52:33 EDT 2012
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
------------------------------------------------------------------------ -
More information about the TriLUG
mailing list