How can I test a variable to see if its in the right format?
The format for the variable would be 'DDMMYYYY HH:MM:SS' and is passed from a command line argument.
Any help would be appreciated
How can I test a variable to see if its in the right format?
The format for the variable would be 'DDMMYYYY HH:MM:SS' and is passed from a command line argument.
Any help would be appreciated
Perhaps try using the touch command, e.g...
MMDD=$(expr substr "$*" 1 4)
YYYY=$(expr substr "$*" 5 4)
hh=$(expr substr "$*" 10 2)
mm=$(expr substr "$*" 13 2)
ss=$(expr substr "$*" 16 2)
if touch -c -t $YYYY$MMDD$hh$mm.$ss dummyfile
then
echo valid
else
echo invalid
fi
Thanks very much
Your help is really appreciated