I have attached an example program that can deal with
the different regex parsing in 3.0.x vs. 3.1.x and
regex sub-expressions. I have tested with
3.1.17 and 3.2.3 successfully. Since creating a
script that actually worked with both bash versions
took me a while, I suspect other people might want
to see an example. This example will split out
3 subexpressions from the input, but does not
include any error checking for bad input. If the
code is incorrect please let me know.
Thanks!
JGH
#! /bin/bash
#
# We need bash 3.x or better
#
if [ -z "${BASH_VERSION:-}" ]
then
printf "This script requires GNU bash (ftp://ftp.gnu.org/gnu/bash)\n"
printf "You need version 3.0 or newer for this script.\n"
exit 1
fi
if [ ${BASH_VERSINFO[0]]} -lt 3 ]
then
printf "This script requires bash >= 3.0; you only have ${BASH_VERSION}\n"
exit 1
fi
if ((BASH_VERSINFO[1]==2))
then
if ((BASH_VERSINFO[2]<3))
then
printf "The regex implementation in bash 3.2.0 through 3.2.2 has issues.\n"
printf "Please apply the patches
(ftp://ftp.gnu.org/gnu/bash/bash-3.2-patches/)\n"
printf "and then try running this script again.\n"
exit 1
fi
NEW_REGEX=1
else
NEW_REGEX=0
fi
REGEX1[0]='"([ATCSBH]) ([^ ]+) (.*)"'
REGEX1[1]='([ATCSBH])\ ([^\ ]+)\ (.*)'
testmeout() {
local i
eval "[[ \"${1}\" =~ ${REGEX1[${NEW_REGEX}]} ]]"
for ((i=1;i<${#BASH_REMATCH[*]};++i))
do
printf "Subexpression %d is \"%s\"\n" ${i} "${BASH_REMATCH[${i}]}"
done
}
printf "Testing with ${BASH_VERSION}\n"
testmeout "A Today mypackage"
exit 0
_______________________________________________
Bug-bash mailing list
Bug-bash@gnu.org
http://lists.gnu.org/mailman/listinfo/bug-bash