mardi 15 septembre 2020

How to write multiple "and", "or" conditions in a if-statement in shell?

I am trying to make this work. I need to check if col_numbers and ok_numbers are same, then print WORKS unless col_numbers or ok_numbers both are zero. How do I test this? I tried this but failed to get what is expected.

Condition1 ( I don't want to print `WORKS!` when both are zero though they both are equal):
ok_numbers=0
col_numbers=0

Condition2 (I want to print `WORKS!` because both are non-zero and equal):

ok_numbers=4
col_numbers=4

What am I missing in my code below?

  if [ ( ${col_numbers} -eq ${ok_numbers} ) -a (( ${col_numbers} -ne 0 ) -o ( ${ok_numbers} -ne 0 )) ]; then
    echo "WORKS!"
  fi

Aucun commentaire:

Enregistrer un commentaire