by spicybright · 4y ago · 0 comments
There was a post a bit ago that had a one liner for a basic web server using net cat:
while : ; do cat page.html | nc -l 80; done while :; do nc -l 80 < page.html; doneI 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.
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.
Maybe it's lighter than cat, but whatever code path is triggered by the `<` can't be zero-cost
while :; do <page.html nc -l 80 ; done