本文介绍了管|重定向>优先级的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 我想说清楚管道什么时候开始|或重定向 在命令中优先?I want to make clear when does pipe | or redirection < > takes precedence in a command?这是我的想法,但需要确认它是如何工作的.This is my thought but need confirmation this is how it works.示例 1:sort < names | headThe pipe runs first: names|head then it sorts what is returned from names|head示例 2:ls | sort > out.txtThis one seems straight forward by testing, ls|sort then redirects to out.txt示例 3:Fill in the blank? Can you have both a < and a > with a | ???推荐答案在语法分组方面,> 和 具有更高的优先级;也就是说,这两个命令是等价的:In terms of syntactic grouping, > and < have higher precedence; that is, these two commands are equivalent:sort < names | head( sort < names ) | head就像这两个:ls | sort > out.txtls | ( sort > out.txt )但是从顺序上来说,|是先执行的;所以,这个命令:But in terms of sequential ordering, | is performed first; so, this command:cat in.txt > out1.txt | cat > out2.txt将填充out1.txt,而不是out2.txt,因为>out1.txt 在| 之后 执行,因此取代它(因此没有输出通过管道输出到cat> out2.txt).will populate out1.txt, not out2.txt, because the > out1.txt is performed after the |, and therefore supersedes it (so no output is piped out to cat > out2.txt).同样,这个命令:cat < in1.txt | cat < in2.txt将打印in2.txt,而不是in1.txt,因为在|之后执行,因此取代它(所以没有输入从cat输入).will print in2.txt, not in1.txt, because the < in2.txt is performed after the |, and therefore supersedes it (so no input is piped in from cat < in1.txt). 这篇关于管|重定向>优先级的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 07-26 10:59