I am trying to follow Bash Cookbook to learn about Bash Scripting. I am on example 6.8 Testing with Regular Expression.
I have the following script:
#!/usr/bin/env bash
# cookbook filename: trackmatch
for CDTRACK in *
do
if [[ "$CDTRACK" =~ "([[:alpha:][:blank:]]*)- ([[:digit:]]*) - (.*)$" ]]
then
echo ${BASH_REMATCH[2]}
else
echo Error $CDTRACK
fi
done
I apply this to a couple of files in my directory:
Ludwig van Beethovern - 02 - Adagio un poco mosso.ogg
Ludwig van Beethovern - 01 - Allegro.ogg
I always get an error returned. The issue appears to be with ([[:alpha:][:blank:]]*)- ([[:digit:]]*) - section of code. When I do have the if statement as: if [[ "$CDTRACK" =~ "(.*)$" ]] then there is no error.
Any thoughts as to what I am doing wrong?
I am running the code on AWS, Bash v 4.2
([[:ascii:]]*)it also doesn't work so I don't think that is the issue ...