Test expression for [[ ... ]] conditional constructs.
This represents bash's extended test expression using double bracket notation. The expression tokens are passed directly to the test expression builtin for evaluation.
Examples
# [[ -f file ]]
%TestExpression{
expression: ["-f", "file"]
}
# [[ $x -eq 5 ]]
%TestExpression{
expression: [%Word{...}, "-eq", "5"]
}
# [[ -f file1 && -f file2 ]]
%TestExpression{
expression: ["-f", "file1", "&&", "-f", "file2"]
}Expressions are composed of the same primaries used
by the test builtin, and may be combined using the following operators:
( EXPRESSION )- Returns the value of EXPRESSION! EXPRESSION- True if EXPRESSION is false; else falseEXPR1 && EXPR2- True if both EXPR1 and EXPR2 are true; else falseEXPR1 || EXPR2- True if either EXPR1 or EXPR2 is true; else false
When the == and != operators are used, the string to the right of
the operator is used as a pattern and pattern matching is performed.
When the =~ operator is used, the string to the right of the operator
is matched as a regular expression.
The && and || operators do not evaluate EXPR2 if EXPR1 is sufficient to determine the expression's value.
Exit Status: 0 or 1 depending on value of EXPRESSION.
Operator precedence: ! > && > ||
Reference: https://cgit.git.savannah.gnu.org/cgit/bash.git/plain/builtins/test.def?h=bash-5.3
Summary
Types
@type t() :: %Bash.AST.TestExpression{ exit_code: 0..255 | nil, expression: [Bash.AST.Word.t() | String.t()], meta: Bash.AST.Meta.t(), state_updates: map() }