#! /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