jeudi 24 mai 2018

Bash script accepting variables in valid number format

I would like to ask if there is a way to validate if the variable passed is in this kind of sample format "06-10" or "10-01". It was really a challenge to me on how to start and echnically the "6-10" stands for "June 10" and "10-01" stands as "October 1", overall it needs to have like of a "Month-Day" valid in number format. I would like to have an if-then statement that would validate if the variables passed are in correct, something like these:

#!/bin/bash
DATE1=$1
DATE2=$2
if [DATE1 is not in correct format] || [DATE2 is not in correct format]
 then
  echo "Correct format"
  echo "DATE1 = $DATE1"
  echo "DATE2 = $DATE2"
 else
  echo "Not correct format"
   exit 1
fi

Aucun commentaire:

Enregistrer un commentaire