My date format is yyyy-mm-dd-hh:mm:ss
How do I check my input?
It should be something like this:
#!/bin/bash
read -p "Date (format yy-mm-dd-HH-MM-SS): " input
check=$(date +"%Y-%m-%d-%H:%M:%S")
if [ $input -eq $check ]; do
echo "Right!"
else
echo "False!"
fi
But that doesn’t check the date It compares my input with the real date.
Best Regards
Vince
Edited apr 2016!
See further (stronger method)
Original post
Try:
or
Well tested:
Edit add
For testing a date, you could:
and/or
Using boot method let you confirm format and reliability of input
Stronger method
If you want to check input, there is a finer method:
This will dump
adatearray variable:From there, you could re-validate day number:
The only thing not tested there is field length if
will work, then
will work too (there is only one digit in day field).
If needed, you could change the line:
for
Nota: Year field is arbitrarily limited between 2000 and 2100, but this is easy to understand/change.