Validate date format in a shell script

后端 未结 12 1808
我在风中等你
我在风中等你 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

    How about using awk:

    echo "31/12/1999" | awk  -F '/' '{ print ($1 <= 31 && $2 <= 12 && match($3, /^[1-9][1-9][1-9][1-9]$/)) ? "good" : "bad" }'
    

    It prints "good" if its valid date else prints "bad"

提交回复
热议问题