Conditional command

The syntax of the [[...]] command is

[[ expression ]]

It returns a status of 0 or 1 depending on the evaluation of the conditional expression expression. The format of a conditional expression is the same as the expressions evaluated by the test utility. qsh performs tilde expansion, parameter expansion, arithmetic expansion, command substitution, and quote removal on expression before it is evaluated.

Examples

  1. A conditional command that uses a command substitution.
    if [[ $(grep -c apple fruits.txt) -eq 0 ]]
    then
      echo There are no apples in fruit.txt
    fi