Validate date format in a shell script

后端 未结 12 1747
我在风中等你
我在风中等你 2020-11-29 11:11

I have to create a Shell Script wherein one of the parameters will be the date in the format dd/mm/yyyy. My question is, how can I check if the Date passed as parameter real

12条回答
  •  野趣味
    野趣味 (楼主)
    2020-11-29 12:01

    Blockquote

    DATE = "$*"
    
    [[ "${DATE}" != @(((([123][0]|[012][1-9])|3[1])?([ \/._-])(0[13578]|1[02])?([ \/._-])(19|20)[0-9][0-9])|(([123][0]|[012][1-9])?([ \/._-])\
    (0[469]|11)?([ \/._-])(19|20)[0-9][0-9])|(([12][0]|[01][1-9]|2[1-8])?([ \/._-])02?([ \/._-])(19|20)[0-9][0-9])|(29?([ \/._-])02?([ \/._-])\
    (19|20(0[48]|[2468][048]|[13579][26])))) ]] && echo error || echo good)
    

提交回复
热议问题