什么是管道中的BASH是如何工作的一个简单的解释? [英] What is a simple explanation for how pipes work in BASH?

查看:160
本文介绍了什么是管道中的BASH是如何工作的一个简单的解释?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我经常使用的bash管道,例如:

I often use pipes in BASH, e.g.:

dmesg | less

虽然我知道这是什么输出,需要的dmesg ,让我通过它滚动与,我做的不明白什么 | 在做什么。难道仅仅&GT相反;

Although I know what this outputs, it takes dmesg and lets me scroll through it with less, I do not understand what the | is doing. Is it simply the opposite of >?


  • 是否有一个简单的,或隐喻解释是什么 | 确实

  • 当几个管道在一行上使用善有善报?

  • 是无处不在它出现在一个bash脚本管一致的行为?

推荐答案

UNIX管道连接STDOUT(标准输出)的第一道工序到第二的STDIN(标准输入)的文件描述符。会发生什么然后是,当第一个进程写入其STDOUT,该输出可以立即(从STDIN)由第二过程读出。

A Unix pipe connects the STDOUT (standard output) file descriptor of the first process to the STDIN (standard input) of the second. What happens then is that when the first process writes to its STDOUT, that output can be immediately read (from STDIN) by the second process.

使用多个管道没有比使用单管不同。每根管子是独立的,并简单地连接相邻进程的STDOUT和STDIN。

Using multiple pipes is no different than using a single pipe. Each pipe is independent, and simply links the STDOUT and STDIN of the adjacent processes.

您的第三个问题是有点含糊不清。是的,管道,因为这样,到处都是一致的bash脚本。然而,管道符 | 可以重新present不同的事情。双管( || ),再presents的或运算符,例如

Your third question is a little bit ambiguous. Yes, pipes, as such, are consistent everywhere in a bash script. However, the pipe character | can represent different things. Double pipe (||), represents the "or" operator, for example.

这篇关于什么是管道中的BASH是如何工作的一个简单的解释?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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