问题
Does PowerShell have an equivalent to this command construct from sh
(and derivatives):
$ cmd1 && cmd2
where cmd2
is only run when cmd1
exits sucessfully?
I know you can combine commands with a semicolon. However, this disregards the exit status of commands.
回答1:
There is no direct analog to && or ||. There are several discussions on alternatives though. Here is one example:
conditional execution (&& and ||) in powershell
回答2:
Try this:
$errorActionPreference='Stop'; cmd1; cmd2
来源:https://stackoverflow.com/questions/11104197/chain-commands-on-the-powershell-command-line-like-posix-sh