In my bash script I want to check that date values provided via command line arguments by the user, have yyyy-mm-dd format. So for example, the date August 10th 2020 has to be written as 2020-08-10. Here is the test that I've written for pattern matching via a regular expression:
#!/usr/bin/bash
dateval="2020-08-10"
regexp="^[0-9]{4}-[0-9]{2}-[0-9]{2}$"
if [[ ! "${dateval}" =~ "${regexp}" ]]
then
echo "Date format is not valid"
else
echo "Date format is valid"
fi
This prints "Date format is not valid" and I don't understand why as the date value being tested is indeed in good format. Could you kindly make some clarification and indicated what I misunderstand?