Reputation: 1225
curl -sL https://deb.nodesource.com/setup_8.x | bash -
apt-get install -yq nodejs
We are using this command to update node. I ran just bash -
in terminal and that just returned a new line. I have looked online and cannot find or understand what adding bash -
to apt-get
does in our update.sh file.
Upvotes: 0
Views: 282
Reputation: 2614
In your code, the first line downloads a script from Node servers. It is a Bash script, and Curl will print it to the standard output, so we use the pipe operator to send it to Bash. The dash (-), is the standard method of telling a program that it should read from the standard input, rather than from a file. The pipe operator works by sending the standard output of a command as the standard input to the next, so Bash will receive the script downloaded from Node servers from input and treat it like if it was a file, so it will execute it.
If you were to run the command without the | bash -
at the end, you'd see a long Bash script written in your terminal. If you try to run echo "echo Hi" | bash -
you'll see "Hi" in your terminal, since you're first printing echo Hi
on screen, then sending it to Bash to execute it, which will print "Hi".
The second command does the regular installation of Node.js using your package manager.
So basically you're running a script from Node servers performing some preinstall tasks (probably adding apt keys from Node and installing dependencies) and then you're actually installing Node.js.
Upvotes: 1