if
ARES System Manual: exec Shell

(input) @if [not] <expression> then <...>
(input) @if [not] <str1> is <str2> then <...>
(input) @if [not] <needle> in <haystack> then <...>
(input) @if [not] exists <file> then <...>

Evaluates <expression> and executes the command <...> if the result was non-zero.

The word then is used to mark the end of the expression in the if statement, and has no significance outside this context.

The word is can be used to test for string equality. This is not currently very reliable, as variables are substituted before evaluation and are not escaped. The special tokens "" and %empty are interpreted as empty strings if they appear on either side of the word is.

The word in can be used to check if a key <needle> is present in a JSON object <haystack>. It does not work for strings, arrays, or any other datatype.

The word exists can be used to check if a file <file> is present in local storage. For a more general solution that includes remote storage, try xset <var> fs info <file> followed by if not $<var> is %undefined then <...>. See xset.

The word not may be added directly after if to negate the evaluation.

See expressions for more information.

Shell built-in command: This command is part of the exec shell and does not have a corresponding system binary. It must be used shell scripts without a preceding @ and cannot be called directly with the system invoke() API.

To use this command with invoke(), use the syntax exec if <expression> then <...>.