[Apple] Explanation /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Solution 1:

  • /bin/bash executes a new instance of bash
  • -c passes one or several commands to be executed
  • $(...) runs the command within () and returns its result (Command Substitution)
  • curl ... gets the file specified in the URL

So basically bash gets called to execute the content of the file fetched by curl.

Some things you may try to understand this in more detail

  • run curl ... to see what curl returns, or curl ... | less to examine it in more detail
  • run /bin/bash -c 'echo "Welcome to bash"'
  • read man bash and man curl

Solution 2:

I want to add that if you're security conscious, you should never cut-n-paste such a command from a web site to run on your computer like that.

The HomeBrew project is a well-known and respected piece of software so I'm not saying that there is anything inherently wrong with installing it. However, their web site could be compromised in the future, where this command no longer performs as intended.

Also in general it is a good idea to not learn a habit of just cut-n-pasting commands like this to install software.

A security conscious way of handling this situation would be to download the install.sh file to your computer first. Then you need to read it through and understand what it does - and only then run it. Note that it is not a good idea to merely browse the install.sh file in a browser to determine that it is okay, as it is actually possible for a malicious server to detect whether or not you're browsing the script in a browser, or actually downloading to immediately execute it - and they could swap out the contents underneath you.

The main problem here is ofcourse that few people will know how to read and understand shell scripts.