Post History
I won’t repeat the points mentioned in Ordoviz’s answer, but there’s another important aspect which is often forgotten: when you pipe a script to a shell (or pass it as an argument to -c), whatever...
Answer
#2: Post edited
I won’t repeat the concerns raised in [Ordoviz’s answer](https://linux.codidact.com/posts/292138/292146#answer-292146), but there’s another important aspect which is often forgotten: when you pipe a script to a shell (or pass it as an argument to `-c`), whatever is downloaded will be executed, even if the download is incomplete. This can lead to frustration, hilarity, or disaster (think of an unfortunately truncated `rm`…).- Authors of scripts intended for execution in this way can guard against this by making sure that the script only runs if it’s complete. There are a couple of techniques to do this. [Asahi Linux’s bootstrap script](https://github.com/AsahiLinux/asahi-installer/blob/5f0814ba90d2814081c2e9ed516675dd75ab3c6e/scripts/bootstrap.sh#L4) relies on the fact that an `if` block is entirely parsed before being run. Other scripts define their contents as one or more functions first, and have the function call which kicks everything off as the last line of the script. As far as I can tell, [the Homebrew installation script](https://github.com/Homebrew/install/blob/master/install.sh) doesn’t guard against truncation.
- I won’t repeat the points mentioned in [Ordoviz’s answer](https://linux.codidact.com/posts/292138/292146#answer-292146), but there’s another important aspect which is often forgotten: when you pipe a script to a shell (or pass it as an argument to `-c`), whatever is downloaded will be executed, even if the download is incomplete. This can lead to frustration, hilarity, or disaster (think of an unfortunately truncated `rm`…).
- Authors of scripts intended for execution in this way can guard against this by making sure that the script only runs if it’s complete. There are a couple of techniques to do this. [Asahi Linux’s bootstrap script](https://github.com/AsahiLinux/asahi-installer/blob/5f0814ba90d2814081c2e9ed516675dd75ab3c6e/scripts/bootstrap.sh#L4) relies on the fact that an `if` block is entirely parsed before being run. Other scripts define their contents as one or more functions first, and have the function call which kicks everything off as the last line of the script. As far as I can tell, [the Homebrew installation script](https://github.com/Homebrew/install/blob/master/install.sh) doesn’t guard against truncation.
#1: Initial revision
I won’t repeat the concerns raised in [Ordoviz’s answer](https://linux.codidact.com/posts/292138/292146#answer-292146), but there’s another important aspect which is often forgotten: when you pipe a script to a shell (or pass it as an argument to `-c`), whatever is downloaded will be executed, even if the download is incomplete. This can lead to frustration, hilarity, or disaster (think of an unfortunately truncated `rm`…). Authors of scripts intended for execution in this way can guard against this by making sure that the script only runs if it’s complete. There are a couple of techniques to do this. [Asahi Linux’s bootstrap script](https://github.com/AsahiLinux/asahi-installer/blob/5f0814ba90d2814081c2e9ed516675dd75ab3c6e/scripts/bootstrap.sh#L4) relies on the fact that an `if` block is entirely parsed before being run. Other scripts define their contents as one or more functions first, and have the function call which kicks everything off as the last line of the script. As far as I can tell, [the Homebrew installation script](https://github.com/Homebrew/install/blob/master/install.sh) doesn’t guard against truncation.