Bash/sh-&&之间的差异和 ; [英] Bash/sh - difference between && and ;

查看:97
本文介绍了Bash/sh-&&之间的差异和 ;的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通常使用;在一行中组合多个命令,但是有些人更喜欢&&.有什么区别吗?例如,cd ~; cd -cd ~ && cd -似乎是一样的东西.哪个版本更便于携带,例如会被bash子集(例如Android的shell左右)支持吗?

I normally use ; to combine more than one command in a line, but some people prefer &&. Is there any difference? For example, cd ~; cd - and cd ~ && cd - seems to make the same thing. What version is more portable, e.g. will be supported by a bash-subset like Android's shell or so?

推荐答案

如果先前的命令失败并显示;,则第二个命令将运行.

If previous command failed with ; the second one will run.

但是使用&&时,第二个将无法运行.

But with && the second one will not run.

这是操作之间的惰性"逻辑"AND"操作数.

This is a "lazy" logical "AND" operand between operations.

这篇关于Bash/sh-&&之间的差异和 ;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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