Pipe multiple commands into a single command

后端 未结 3 1089
北海茫月
北海茫月 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 15:48

    In Windows it would be as follow: (echo zzz & echo aaa & echo kkk) | sort

    Or if it is inside a batch file it can be mono line (like sample) as well as multiline:

    (
     echo zzz
     echo aaa
     echo kkk
    ) | sort
    

    Note: The original post does not mention it is only for Linux, so I added the solution for Windows command line... it is very useful when working with VHD/VHDX with diskpart inside scripts (echo diskpart_command) instead of the echo on the same, but let there the echo, there is also another way without echos and with > redirector, but it is very prone to errors and much more complex to write (why use a complicated prone to errors way if exists a simple way that allways work well)... also remember %d% gives you the actual path (very useful for not hardcoding the path of VHD/VHDX files).

提交回复
热议问题