Linux “|”是什么意思 在终端命令行中是什么意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/12400371/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 14:20:25  来源:igfitidea点击:

What does "|" mean in a terminal command line?

linuxbashterminal

提问by frazman

Sorry for posting it here, but Google does a very bad job when searching for symbols.

很抱歉在这里发布它,但谷歌在搜索符号时做得非常糟糕。

What does the "|" mean in:

“|”是什么意思 意思是:

"some string" | someexecutable.py

采纳答案by Jonathan Leffler

It is the pipe symbol. It separates two programs on a command line (see Pipelinesin the bashmanual), and the standard output of the first program (on the LHS of the pipe) is connected to the standard input of the second program (on the RHS of the pipe).

它是管道符号。其分离的命令行(见关于两个节目Pipelinesbash手册),并且所述第一程序的标准输出(在管的左轴)被连接到第二程序的标准输入(在管的RHS)。

For example:

例如:

who | wc -l

gives you a count of the number of people or sessions connected to your computer (plus one for the header line from who). To discount the header line:

为您提供连接到您的计算机的人数或会话数(加上 1 的标题行who)。要打折标题行:

who | sed 1d | wc -l

The input to sedcomes from who, and the output of sedgoes to wc.

to 的输入sed来自who,而 的输出sedwc

The underlying system call is pipe(2)used in conjunction with fork(), dup2()and the exec*()system calls.

底层系统调用pipe(2)fork(),dup2()exec*()系统调用结合使用。

回答by P.P

It's called pipe. It gives the stdout of the first command ("some string") as the stdin to the second command (someexecutable.py).

它被称为pipe。它将第一个命令 ( "some string")的标准输出作为第二个命令 ( someexecutable.py)的标准输入。

回答by mehulved

| is a pipe. It sends output of one command as input of the next. It is explained here http://www.ibm.com/developerworks/linux/library/l-lpic1-v3-103-4/#3-pipes

| 是一个管道。它将一个命令的输出作为下一个命令的输入发送。这里解释了http://www.ibm.com/developerworks/linux/library/l-lpic1-v3-103-4/#3-pipes