What does -o mean in an "if"?

13,222

Solution 1

As you can see in the Linux Documentation Project page about if, -o stands for the logical operator OR. In your case, the variable sorszam is checked whether it equals to 1, 2, or 3.

Solution 2

As you should know [ is an equivalent to test built-in command.

$ help [
[: [ arg... ]
    This is a synonym for the "test" builtin...

so you should have a look at help test | grep -- "-o ":

EXPR1 -o EXPR2 True if either expr1 OR expr2 is true.

Solution 3

-eq is an arithmetic binary operator that returns true if both numbers are equal.

-o is an or, you can can string it together with -eq to do multiple comparisons in one line.

Source

Share:
13,222

Related videos on Youtube

Huntyr94
Author by

Huntyr94

Updated on September 18, 2022

Comments

  • Huntyr94
    Huntyr94 almost 2 years

    What is -o after -eq in the mentioned code:

    ...[ $sorszam -eq 0 ] && min1=$ertek; [ $sorszam -eq 1 -o $sorszam -eq 2 -o $sorszam -eq 3 ] && [ $ertek -lt $min1 ] && min1=$ertek...

    • chepner
      chepner about 7 years
      Note that -o is considered obsolete, and the correct way to write new code would be to use [ "$sorszam" -eq 1 ] || [ "$sorszam" -eq 2 ] || [ "$sorszam" -eq 3 ] instead.
  • Huntyr94
    Huntyr94 about 7 years
    Ah, so it is just an "or". Thanks the documentation, didn't know there was such thing.