mic*_*lpm 21 if-statement fish
我想用bash做什么:
> if true; then echo y; else echo n; fi
y
> if false; then echo y; else echo n; fi
n
> if false || true; then echo y; else echo n; fi
y
Run Code Online (Sandbox Code Playgroud)
现在尝试用鱼:
> if true; echo y; else; echo n; end
y
> if false; echo y; else; echo n; end
n
# Here 'or true' are just two arguments for false
> if false or true; echo y; else; echo n; end
n
# Here 'or true;' is a command inside the if
> if false; or true; echo y; else; echo n; end
n
# Can't use command substitution instead of a command
> if (false; or true); echo y; else; echo n; end
fish: Illegal command name “(false; or true)”
Run Code Online (Sandbox Code Playgroud)
我怎么能有两个条件if
?
ter*_*rje 24
另外两种方法:
方法一:
if begin false; or true; end
echo y
else
echo n
end
Run Code Online (Sandbox Code Playgroud)
方法二:
false; or true
and echo y
or echo n
Run Code Online (Sandbox Code Playgroud)