14

I have to run this command to install NPM. What does it do? What is the | at the end?

curl https://raw.githubusercontent.com/creationix/nvm/v0.23.2/install.sh | bash

Also, am I running UNIX-like commands in Bash? Why does this work? Is it that Bash is a UNIX-command compatible interface for the terminal?

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
Jwan622
  • 11,015
  • 21
  • 88
  • 181
  • 1
    `curl` retrieves the indicated file, which happens to be a shell script, and that is piped into `bash` which is the shell program that will execute it. If you do a Google search on "what is bash" you'll find may explanations. But, yes, `bash` is one of several different Unix shell implementations. – lurker Oct 30 '15 at 11:15
  • @Zloj In the general case, that's true. In the specific case of a well-known publisher and a trusted relationship as well as some reasonable way to vet the code, it's not quite that bad (but still bad). – tripleee Oct 30 '15 at 12:54
  • Possible duplicate of [What does "|" mean in a terminal command line?](https://stackoverflow.com/questions/12400371/what-does-mean-in-a-terminal-command-line) – Guillaume Georges Jul 03 '18 at 08:39

1 Answers1

15

In bash (and most *nix shells) the | (pipe) symbol takes the output from one command and uses it as the input for the next command.

What you are doing here is using curl to retrieve the install.sh file and then output its contents into bash, which is a shell that will execute the contents of install.sh

In short, you are downloading and running the install.sh script.

Chris Tompkinson
  • 588
  • 7
  • 18
  • 3
    What do you mean "input for the next command"? Does the "bash" command take input? – Jwan622 Oct 30 '15 at 13:43
  • 4
    All *nix programs have three streams, the standard in, the standard out and standard error. When you pipe you passing the input to the standard in which the program can then use, similar to a parameter. an example would be ```cat file | grep keyword | less``` Which would print the contents of a file, then filter the contents of the file and then present the result in a screen. http://stackoverflow.com/questions/9834086/what-is-a-simple-explanation-for-how-pipes-work-in-bash does a better job of explaining it. – Chris Tompkinson Oct 30 '15 at 13:47