I basically want to do the following in Bash 3.1 under Windows (Git Bash):
#!/bin/bash
#set -x
shopt -s extglob
shopt -s nocasematch
declare file='[Vol 01] - 04 - This message'
declare filesafe="${file}"
declare pattern='\[Vol ([0-9]+)\] - ([0-9]+) -*'
if [[ "${file}" =~ $pattern ]]; then
echo "regexp: $(printf "%s %-2d %-3d" "${filesafe}" "${BASH_REMATCH[1]}" "${BASH_REMATCH[2]}" ) - - -"
else
echo "failed: $(printf "%s" "${filesafe}") - - - - -"
fi
The =~
does not work because it does not exists in this version of Bash.
Note: the script works with Bash 4.3.33 in Gentoo.
Version of Git & Bash are the following:
$ git --version ; bash --version
git version 1.9.5.msysgit.1
GNU bash, version 3.1.23(6)-release (i686-pc-msys)
Copyright (C) 2005 Free Software Foundation, Inc.
In the sole documentation on Bash 3.1 that I could find, the version is:
This is Edition 3.1-beta1, last updated 5 September 2005, of The GNU Bash Reference Manual, for Bash, Version 3.1-beta1.
This documentation state the =~
is available:
An additional binary operator, '=~', is available, with the same precedence as '==' and '!='.
Did I miss something like some option using shopt?