shell 检测日期格式是否合法

function  if_query_date_true(){
if echo $1 | grep -Eq "[0-9]{4}-[0-9]{2}-[0-9]{2}" && date -d $1 +%Y%m%d > /dev/null 2>&1 ;
then echo "success";
else
        echo "输入的日期格式不正确,应该为yyyy-mm-dd"
        exit 1;
fi
}
原文地址:https://www.cnblogs.com/students/p/13600474.html