I wrote this small unix shell script to validate the date format. My script should check whether the string is in YYYYMMDDHHMISS format . If it is not in this format , it should send an error message .
For example, I declared an variable a and assigned an value to it.
a=20150620223405 date "+%Y%m%d%H%M%S" -d $a > /dev/null 2>&1 if [ $? -ne 0 ] then echo "Invalid format" else echo "Valid format" fi
It always shows "Invalid" .I want to know what is the mistake here and how to proceed.. thanks