在PowerShell命令行上链接命令(例如POSIX sh&&) [英] Chain commands on the PowerShell command line (like POSIX sh &&)

查看:57
本文介绍了在PowerShell命令行上链接命令(例如POSIX sh&&)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

PowerShell是否具有与 sh (及其派生词)中的此命令等效的结构:

Does PowerShell have an equivalent to this command construct from sh (and derivatives):

$ cmd1 && cmd2

其中 cmd2 仅在 cmd1 是否成功退出?

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.

推荐答案

&&没有直接的相似之处。或||。尽管有一些关于替代方案的讨论。这是一个示例:

There is no direct analog to && or ||. There are several discussions on alternatives though. Here is one example:

有条件执行(&&和||)

这篇关于在PowerShell命令行上链接命令(例如POSIX sh&&)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆