命令执行顺序有问题
cat <<lim | sleep 5 | ls >file2 | cat <<lim | grep wow | cat <<lim
在此示例中,我不明白为什么睡眠执行在执行结束时开始。如果你们中的任何一个有来源或解释此处的文档的工作以及他如何从输入中保存数据,请分享。
cat <<lim | sleep 5 | ls >file2 | cat <<lim | grep wow | cat <<lim
In this example, I don't understand why sleep execution begins at the conclusion of the execution. If any of you have a source or explanation of how this here document works and how he saves the data he gets from input, please share.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不要这样做。
a pipe 字符基本上将其左操作数的Stdout连接到其右操作数的stdin上。那是的。
您为什么要 这样做?
将
&gt; file2
放在ls
将其输出重定向到file2
。管道上没有什么。
在
cat
上放置一个doc,将其输入从 shere 的部分重定向,因此,它再次忽略了管道。你为什么在这里有管道?如果您只希望这些事情同时发生,但是
我承认我真的不知道您做了什么。
您是否期望改变管道行为的本地文件名称WOW和LIM?我不能说。
尝试查看 this> thisce 。希望他们会帮助。
详细说明 -
任何过程的输入默认为FD0。
通常是控制台,例如,您的键盘。
从文件(
cat&lt; file
)重定向将FD0连接到该文件。管道数据是另一种重定向的形式,替换了FD0-
例如,
echo foo | GREP -O OO
应该输出oo
。这里是输入重定向的另一种形式。
给定流的命令行重定向均按顺序实现。因此,给定
Echo 2&gt; 2
,但是如果您开始混合它们,则上次发生的任何重定向将有效。
这些相同的原则适用于输出重定向。
这是允许调整文件描述符的原理...
这试图列出我们上面使用的文件2和一个不存在的文件,名为
bogus
。它将将fd2(错误流)重定向到当前fd1的任何地方,默认为“ stdout”;然后,它将FD1重定向到名为log
的文件,仅留下错误流到Stdout。然后, pipe 字符将stdout连接到tee
程序的stdin,该程序将其复制到名为err
的文件以及其自己的stdout,它被重定向回到stderr流。结果是2个报告到
log
,但是bogus
的错误都向屏幕(在stderr)和err
文件报告。 。但是,除非您知道为什么并且 您在做什么,否则不要这样做。
DON'T DO THIS.
A pipe character basically attaches the stdout of its left operand to the stdin of its right operand. That's what it is for.
Why would you ever do this?
Putting
>file2
on thels
redirects its output tofile2
.There is nothing for the pipe.
putting a here-doc on
cat
redirects its input from the HERE portion, so again, it ignores the pipe. Why do you have pipes here at all?If you just want these things to happen simultaneously, then
but I confess I really have no idea what you did want.
Were there local files names wow and lim that you expected to change the behavior of the pipelines? I can't tell.
Try looking over these. Hope they help.
To elaborate -
input to any process is by default on fd0.
That is usually the console, e.g., your keyboard.
Redirecting from a file (
cat < file
) attaches fd0 to that file.Piping data in is another form of redirection, replacing fd0 -
e.g.,
echo foo | grep -o oo
which should outputoo
.here-docs are another form of input redirection.
Command-line redirections for a given stream are all implemented in order, as given. Thus, given
echo 2>2
,But if you start mixing them, whichever redirection happened last will be in effect.
These same principles apply for output redirections.
This is the principle that allows shuffling file descriptors...
This tries to list the file 2 we used above and a non-existent file named
bogus
. It will redirect fd2, the error stream, to wherever fd1 is currently going, which defaults to "stdout"; Then it redirects fd1 to the file namedlog
leaving only the error stream going to stdout. Then the pipe character connects stdout to the stdin of thetee
program, which duplicates it to the file namederr
as well as its own stdout, which is redirected back to the stderr stream.The result is that the 2 reports to
log
, but the error forbogus
reports both to the screen (on stderr) and to theerr
file.But don't do this unless you KNOW WHY and exactly what you are doing.