加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

bash – 管|重定向<>优先级

发布时间:2020-12-15 18:52:31 所属栏目:安全 来源:网络整理
导读:我想清楚什么时候管道|或重定向在命令中优先使用? 这是我的想法,但需要确认这是它的工作原理. 示例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 straig
我想清楚什么时候管道|或重定向>在命令中优先使用?

这是我的想法,但需要确认这是它的工作原理.

示例1:

sort < names | head
The pipe runs first:  names|head   then it sorts what is returned from names|head

示例2:

ls | sort > out.txt
This 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 | ???
在语法分组方面,>和&优先权较高;也就是说,这两个命令是等效的:
sort < names | head
( sort < names ) | head

这两个是一样的:

ls | sort > out.txt
ls | ( sort > out.txt )

但是在顺序排序方面首先执行;所以,这个命令:

cat in.txt > out1.txt | cat > out2.txt

将填充out1.txt,而不是out2.txt,因为> out1.txt在|之后执行,因此取代它(因此没有输出被输出到cat> out2.txt).

同样,这个命令:

cat < in1.txt | cat < in2.txt

将打印in2.txt,而不是in1.txt,因为< in2.txt在|之后执行,因此取代它(因此没有输入从cat< in1.txt中输入).

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读