I have the following in my bash script:
if [ $YEAR_MONTH =~ ^[0-9]{4}-(0[1-9]|1[0-2])$]
then
echo "ERROR: Incorrct folder name format, should be <YYYY-mm>"
echo ""
print_instructions
exit 1
fi
The regex is good as best as I can tell, but bash throws this error when I try run it:
myuser@myserver:/opt/myfolder$ ./fetch_logs_from_azure.sh list
./fetch_logs_from_azure.sh: line 51: syntax error near unexpected token `('
./fetch_logs_from_azure.sh: line 51: ` if [ $YEAR_MONTH =~ ^[0-9]{4}-(0[1-9]|1[0-2])$]'
I thought I might need to escape the '-' but that didn't make a difference.
What am I doing wrong?