vendredi 6 septembre 2019

How make multiple if conditions with regex in shell script

I have 2 values, project and tag. I need check if them are empty/null and if project has only characters (except '-') and if tag has only numbers (expect '.').

User actually invert the order of them, first need be project and after tag.

I try invert the regex of $project and $tag if user wrong the order... But nothing happens, no errors and code continue.

if [ -z $project ] || 
   [ -z $tag ] || 
   [[ $project =~ '/^[0-9]+(\.[0-9]+)*$/' ]] || 
   [[ $tag =~ '/^[A-Za-z]+(\-[A-Za-z]+)*$/' ]] ; then
  echo Project or tag wrong, please try again. &&
  echo Example: file.sh project-test 1.99.2
fi

This code no give me errors, but also not do what I need. What I'm doing wrong here?

Aucun commentaire:

Enregistrer un commentaire