美文网首页Linux学习|Gentoo/Arch/FreeBSDLinux学习之路程序员
刨根问底:bash shell中管道和其他命令分隔符的优先级

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

作者: 大神带我来搬砖 | 来源:发表于2018-03-24 17:45 被阅读139次

    一般在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"结合

    相关文章

      网友评论

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

        本文链接:https://www.haomeiwen.com/subject/azaqcftx.html