pub enum Expr {
Show 15 variants
Literal(Value),
VarRef(VarPath),
Interpolated(Vec<StringPart>),
BinaryOp {
left: Box<Expr>,
op: BinaryOp,
right: Box<Expr>,
},
CommandSubst(Box<Pipeline>),
Test(Box<TestExpr>),
Positional(usize),
AllArgs,
ArgCount,
VarLength(String),
VarWithDefault {
name: String,
default: Vec<StringPart>,
},
Arithmetic(String),
Command(Command),
LastExitCode,
CurrentPid,
}Expand description
An expression that evaluates to a value.
Variants§
Literal(Value)
Literal value
VarRef(VarPath)
Variable reference: ${VAR} or ${VAR.field} or $VAR
Interpolated(Vec<StringPart>)
String with interpolation: "hello ${NAME}" or "hello $NAME"
BinaryOp
Binary operation: a && b, a || b
CommandSubst(Box<Pipeline>)
Command substitution: $(pipeline) - runs a pipeline and returns its result
Test(Box<TestExpr>)
Test expression: [[ -f path ]] or [[ $X == "value" ]]
Positional(usize)
Positional parameter: $0 through $9
AllArgs
All positional arguments: $@
ArgCount
Argument count: $#
VarLength(String)
Variable string length: ${#VAR}
VarWithDefault
Variable with default: ${VAR:-default} - use default if VAR is unset or empty
The default can contain nested variable expansions and command substitutions
Arithmetic(String)
Arithmetic expansion: $((expr)) - evaluates to integer
Command(Command)
Command as condition: if grep -q pattern file; then - exit code determines truthiness
LastExitCode
Last exit code: $?
CurrentPid
Current shell PID: $$