重定向用于重定向 stdout/stdin/stderr!
前任:ls > log.txt.
Pipes用于将一个命令的输出作为另一个命令的输入。
前任:ls | grep file.txt
为什么这两个操作员会做同样的事情?
为什么不直接写ls > grep
传递输出,这不也是一种重定向吗?
我意识到 Linux 是“做一件事并把它做好”,所以我错过了更多的逻辑原因。
You do需要区分语法功能 - 并使用>
vs. |
会做得很好。
如果你用过>
in both场景,你怎么知道是否
ls > grep
正在尝试写信给file named grep
或将输入发送到grep
command?
grep
is perhaps not the best example, as you may then be tempted to disambiguate by the presence of grep
's mandatory arguments; however, (optionally) argument-less commands do exist, such as column
.
that other guy https://stackoverflow.com/users/1899640/that-other-guy offers another example in the comments: test
may refer to a test output file or to the argument-less invocation of the standard test command http://pubs.opengroup.org/onlinepubs/9699919799/utilities/test.html.
另一种看待它的方式:
您的建议本质上是使用>
作为通用的发送输出某处运算符,无论目标类型如何(文件与命令)。
然而,仅此而已shifts需要消除歧义,然后在指定时必须消除歧义target- 是要输出的文件还是要运行的命令?
鉴于外壳也有一个implicit消歧功能,当涉及到first一个简单命令的标记 -foo [...]
只调用一个command- 在层次上进行差异化operator - >
用于输出到文件,|
对于发送命令 - 是明智的选择。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)