Search code examples
bash

What does a | (pipe character) do in a shell (bash) command?


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?


Solution

  • In Bash (and most *nix shells), the | (pipe) metacharacter¹ causes the shell to take 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.


    1. A shell metacharacter is a character/symbol with a special meaning to the shell and it causes termination of a word unless it is quoted. For example, |, >, <, etc are shell metacharacters.