Skip to content

Comment on "So that a truncated partial download doesn't end up executing half a script"parent

Comments

A truncated download might happen for all sorts of reasons, like your internet connection dropping while you download the script. If you don't notice you might accidentally run an incomplete script and leave your system in some broken or at least confusing state. They wrapped everything in a main function to prevent that from happening

Browsers typically emit downloads to temporary files until they are complete, then rename them into the final location, to prevent this kind of issue.

Tools like wget or curl often do not. And the shell doesn't when doing something like `curl ... >myscript.sh`.

Sure. Just pointing out that there's a good reason browsers do this.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.