If command

The syntax of the if command is

if list1

then list2

[ elif list3

then list4 ] ...

[ else list5 ]

fi

First, qsh runs list1 and if its exit status is zero then qsh runs list2. Otherwise, each elif list3 is run and if its exit status is zero then qsh runs list4. Otherwise, qsh runs list5.

Examples

  1. An if-then-fi command.
    x=4
    y=9
    if test $x -lt $y 
    then
      echo $x is less than $y
    fi
    
  2. An if-then-else-fi command.
    x=10
    y=9
    if test $x -lt $y
    then
      echo echo $x is less than $y
    else
      echo echo $x is greater than or equal to $y
    fi
    
  3. An if-then-elif-else-fi command.
    x=4
    y=4
    if test $x -lt $y
    then
      echo echo $x is less than $y
    elif test $x -eq $y
    then
      echo $x is equal to $y
    else
      echo $x is greater than or equal to $y
    fi