Operators
For a full list with precedence values, run help operators. See also Operators in the Book.
Arithmetic Operators
+- Plus / Addition-- Minus / Subtraction*- Multiply/- Divide (always returns afloatfor numbers, e.g.10 / 2is5.0)//- Floor Divisionmod- Modulo (floor semantics: the result has the sign of the divisor)**- Pow++- Concatenates two lists, two strings, or two binary values
10 / 4
# => 2.5
-7 // 2
# => -4
-7 mod 3
# => 2
2 ** 10
# => 1024
[1 2] ++ [3]
# => ╭───┬───╮
# => │ 0 │ 1 │
# => │ 1 │ 2 │
# => │ 2 │ 3 │
# => ╰───┴───╯Comparison Operators
==- Equal!=- Not Equal<- Less Than>- Greater Than<=- Less Than or Equal To>=- Greater Than or Equal To
Bitwise Operators
Nushell provides support for these bitwise operators:
bit-or- bitwise orbit-xor- bitwise exclusive orbit-and- bitwise andbit-shl- bitwise shift leftbit-shr- bitwise shift right
Boolean Operators
and- And (short-circuiting)or- Or (short-circuiting)xor- Exclusive ornot- Negates the expression that follows it
Other operators
=~/like- Regex Match / Contains!~/not-like- Not Regex Match / Not Containsin- Is a member of (doesn't use regex)not-in- Is not a member of (doesn't use regex)has- Contains a value of (doesn't use regex)not-has- Does not contain a value of (doesn't use regex)starts-with- Starts Withnot-starts-with- Does not start withends-with- Ends Withnot-ends-with- Does not end with
Assignment Operators
These operators work on mutable variables (declared with mut):
=- Assign+=- Add and assign-=- Subtract and assign*=- Multiply and assign/=- Divide and assign++=- Concatenate and assign
Precedence
From highest to lowest: **; *, /, //, mod; +, -; bit-shl, bit-shr; the comparison operators, the operators in "Other operators" and ++; bit-and; bit-xor; bit-or; not; and; xor; or; and finally the assignment operators.
1 + 2 * 3
# => 7
2 ** 3 ** 2
# => 512Brackets
[ and ]
The brackets can be used to make lists.
[ 1, 2, 3 ]
# => ╭───┬───╮
# => │ 0 │ 1 │
# => │ 1 │ 2 │
# => │ 2 │ 3 │
# => ╰───┴───╯{ and }
The braces can be used to make records and closures.
{ a: 1, b: 2 }
# => ╭───┬───╮
# => │ a │ 1 │
# => │ b │ 2 │
# => ╰───┴───╯( and )
The parentheses can be used to denote sub-expressions.
# This would fail without parentheses
{ a: ('aaa' | str length), b: 2 }
# => ╭───┬───╮
# => │ a │ 3 │
# => │ b │ 2 │
# => ╰───┴───╯