mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-28 12:13:55 +08:00
357d3b8c6d
This promotes "and" and "or" from a type of statement to "job decorators," as a possible prefix on a job. The point is to rationalize how they interact with && and ||. In the new world 'and' and 'or' apply to a entire job conjunction, i.e. they have "lower precedence." Example: if [ $age -ge 0 ] && [ $age -le 18 ] or [ $age -ge 75 ] && [ $age -le 100 ] echo "Child or senior" end
39 lines
966 B
Fish
39 lines
966 B
Fish
logmsg "Basic && and || support"
|
|
|
|
echo first && echo second
|
|
echo third || echo fourth
|
|
true && false ; echo "true && false: $status"
|
|
true || false ; echo "true || false: $status"
|
|
true && false || true ; echo "true && false || true: $status"
|
|
|
|
logmsg "&& and || in if statements"
|
|
|
|
if true || false ; echo "if test 1 ok" ; end
|
|
if true && false ; else; echo "if test 2 ok" ; end
|
|
if true && false ; or true ; echo "if test 3 ok" ; end
|
|
if [ 0 = 1 ] || [ 5 -ge 3 ] ; echo "if test 4 ok"; end
|
|
|
|
logmsg "&& and || in while statements"
|
|
|
|
set alpha 0
|
|
set beta 0
|
|
set gamma 0
|
|
set delta 0
|
|
while [ $alpha -lt 2 ] && [ $beta -lt 3 ]
|
|
or [ $gamma -lt 4 ] || [ $delta -lt 5 ]
|
|
echo $alpha $beta $gamma
|
|
set alpha ( math $alpha + 1 )
|
|
set beta ( math $beta + 1 )
|
|
set gamma ( math $gamma + 1 )
|
|
set delta ( math $delta + 1 )
|
|
end
|
|
|
|
logmsg "Complex scenarios"
|
|
|
|
begin; echo 1 ; false ; end || begin ; echo 2 && echo 3 ; end
|
|
|
|
if false && true
|
|
or not false
|
|
echo 4
|
|
end
|