Pipe multiple commands into a single command

后端 未结 3 1087
北海茫月
北海茫月 2020-12-02 15:00

How can I pipe the stdout of multiple commands to a single command?

Example 1: combine and sort the output of all three echo commands:

echo zzz; ec         


        
3条回答
  •  执念已碎
    2020-12-02 16:01

    Use parentheses ()'s to combine the commands into a single process, which will concatenate the stdout of each of them.

    Example 1 (note that $ is the shell prompt):

    $ (echo zzz; echo aaa; echo kkk) | sort
    aaa
    kkk
    zzz
    


    Example 2:

    (setopt; unsetopt; set) | sort
    

提交回复
热议问题