4 ms·
what is the difference in these two approaches? I always use the pipe, it is intuitive to me to think left-to-right, output of this becomes input of next. But
by skrtskrt 5y ago
what is the difference in these two approaches?
I always use the pipe, it is intuitive to me to think left-to-right, output of this becomes input of next. But I always see stackoverflow answers using the other approach.
- arbitrage 5y agoThe difference is in the first code example, you're launching both cat and nc. In the second block, you're just launching one program that reads input, not two. It's slightly more efficient. I also tend to build large *NIX pipelines using `cat $foo | [...]`, but it's some times regarded as bad form. See: "useless use of cat" for more examples.
- skrtskrt 5y agoAren't you just using another built-in to read the file contents then? Maybe it's lighter than cat, but whatever code path is triggered by the `<` can't be zero-cost
- aidenn0 5y agoIf you want to do left-to-right, you can do that: while :; do <page.html nc -l 80 ; done