Validate date format in a shell script

后端 未结 12 1805
我在风中等你
我在风中等你 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 11:44

    Here's a function to do some data validation this:

    # Script expecting a Date parameter in MM-DD-YYYY format as input
    verifyInputDate(){
        echo ${date} | grep '^[0-9][0-9]-[0-9][0-9]-[0-9][0-9][0-9][0-9]$'
        if [ $? -eq 0 ]; then
             echo "Date is valid"
         else
              echo "Date is not valid"
         fi
    }
    

提交回复
热议问题