'Is this an implicit pipe?
Consider:
./wordcount.py < war_and_peace.txt | sort -grk 2 | head
To my surprise, the following works as well and produces the same output:
./wordcount.py < war_and_peace.txt sort -grk 2 | head
How is the latter command interpreted? Is piping to sort happening implicitly?
Solution 1:[1]
s this an implicit pipe?
No.
How is the latter command interpreted?
The same as
./wordcount.py sort -grk 2 < war_and_peace.txt | head
or
< war_and_peace.txt ./wordcount.py sort -grk 2 | head
or
./wordcount.py sort -grk < war_and_peace.txt 2 | head
A ./wordcount.py command is run with 3 arguments - string sort, string -grk and string 2 with standard input redirected from war_and_peace.txt file. The output of the command is redirected to the input of command head.
The placement of < followed by filename between the command arguments does not matter. It's typical to place is as the last. I like to start commands with < as the first argument, as it's the input, but some people find it confusing.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | KamilCuk |
