Lessons

lesson 07 / 15

Conditions

An if block selects one branch. An optional else block runs when the condition is false.

kongue
mode: "debug"

main {
    if "$mode" == "debug" {
        print "debug build"
    } else {
        print "release build"
    }
}

The common operators are:

  • == equality
  • != inequality
  • =~ regular-expression match
  • || logical OR
  • && logical AND

Values are often quoted in conditions so that interpolation happens before comparison.

kongue
architecture: "x86_64"
mode: "debug"

main {
    if "$architecture" == "x86_64" && "$mode" == "debug" {
        print "debug build for x86_64"
    }

    if "$architecture" =~ e"x86_64|aarch64" {
        print "supported architecture"
    }
}

The e"..." form marks a regular-expression pattern. In the example above, either architecture matches.