if
for core> if {flags} (cond) (then_block) (else_expression)
cond
: condition to checkthen_block
: block to run if check succeedselse_expression
: expression or block to run if check failsinput | output |
---|---|
any | any |
Output a value if a condition matches, otherwise return nothing
>if2<3 { 'yes!' }
yes!
Output a value if a condition matches, else return another value
>if5<3 { 'yes!' } else { 'no!' }
no!
Chain multiple if's together
>if5<3 { 'yes!' } else if4<5 { 'no!' } else { 'okay!' }
no!
Copyright © 2019–2023 The Nushell Project DevelopersLicensed under the MIT License.
https://www.nushell.sh/commands/docs/if.html