“&"的目的是什么?在 shell 命令中? [英] What is the purpose of "&&" in a shell command?

查看:30
本文介绍了“&"的目的是什么?在 shell 命令中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据我所知,在命令之后使用 & 是为了在后台运行它.

As far as I know, using & after the command is for running it in the background.

& 用法示例:tar -czf file.tar.gz dirname &

但是 && 怎么样?(示例)

推荐答案

此外,您还有 || 是逻辑或,还有 ; 只是一个不关心之前命令发生了什么的分隔符.

Furthermore, you also have || which is the logical or, and also ; which is just a separator which doesn't care what happend to the command before.

$ false || echo "Oops, fail"
Oops, fail

$ true || echo "Will not be printed"
$  

$ true && echo "Things went well"
Things went well

$ false && echo "Will not be printed"
$

$ false ; echo "This will always run"
This will always run

可以在此处找到有关此的一些详细信息命令列表 在 Bash 手册中.

Some details about this can be found here Lists of Commands in the Bash Manual.

这篇关于“&"的目的是什么?在 shell 命令中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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