Pipe | Redirection < > Precedence

前端 未结 5 2044
清酒与你
清酒与你 2020-12-13 05:07

I want to make clear when does pipe | or redirection < > takes precedence in a command?

This is my thought but need confirmation this is how it works.

Exa

5条回答
  •  情话喂你
    2020-12-13 05:44

    Corrections:

    Example 1:

    sort < names | head
    

    In this case, input redirect runs first (names are sorted), then the result of that is piped to head.

    In general you can read from left to right. The standard idiom works as follows:

    • Use of input redirection "<" tells the program reads from a file instead of stdin
    • Use of output redirection ">" tells the program to output to a file instead of stdout
    • Use of pipe "program_a | program_b" takes everything that would normally be output by program_a to stdout, and feeds it all directly to program_b as if it was read from stdin.

提交回复
热议问题