Firstly, yes I have read this:
Bash scripting, multiple conditions in while loop
The answer is probably in that post but I'm failing to see it so I hope someone can help. I want to test for two conditions in my while loop, essentially I want to combine these two tests which are currently nested, one's just a regex, and the second is to test if it is actually a valid date:
while ! [[ "$searchDate" =~ ^[0-9]{1,2}[a-zA-Z]{3}[0-9]{4}$ ]]; do
read -p "Enter date in format DDmmmYYYY: " searchDate
while ! (date -d $searchDate); do
read -p "That date doesn't appear to be valid, try again: " searchDate
done
done
I feel like I should be able to write something like:
while [[ ! "$searchDate" =~ ^[0-9]{1,2}[a-zA-Z]{3}[0-9]{4}$ ]] || ( ! date -d $searchDate); do
read -p "There's something funky about that date, try again: " searchDate
but I can't get it to work, I'm not sure if it's my logic that's skewiff, or the way I'm trying to combine the tests (or both!)...