刨根问底:bash shell中管道和其他命令分隔符的优先级

一般在bash中,用“|”作为管道,即pipeline,还可以用“;”之类的分隔符连接多个命令。那么下面这个命令的输出是什么呢?

date; who |wc

根据https://www.gnu.org/software/bash/manual/bashref.html里的说明,管道是’|’或者’|&’分隔的命令

A pipeline is a sequence of one or more commands separated by one of the control operators ‘|’ or ‘|&’

而list是‘;’, ‘&’, ‘&&’或者 ‘||’分隔的管道

A list is a sequence of one or more pipelines separated by one of the operators ‘;’, ‘&’, ‘&&’, or ‘||’, and optionally terminated by one of ‘;’, ‘&’, or a newline.Of these list operators, ‘&&’ and ‘||’ have equal precedence, followed by ‘;’ and ‘&’, which have equal precedence.

因此上面的命令中,”who | wc”作为一个管道,再和前面的”date”结合

    原文作者:大神带我来搬砖
    原文地址: https://www.jianshu.com/p/4853ee8afdd1
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞