-1

This is the command to install Rust:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

what does the | do?

I think that curl downloads a .sh file from this link, and sh somehow executes it. How does it work? It isn't working in my Dockerfile, I need to pass -y to this .sh but I don't know how.

Guerlando OCs
  • 863
  • 10
  • 51
  • 88

2 Answers2

1

Where are you getting these instructions from? It's likely there is documentation that explains how they intend for you to do what you want.

Needless to say, you can pass -y like so:

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y

-s instructs sh to read from stdin even though there are command line arguments (-- -y). The -- is necessary so sh knows to treat -y as an argument to the script, and not a flag for sh itself.


To your actual question, curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs downloads some data from https://sh.rustup.rs and outputs it. If you visit that URL, you'll see the contents are a shell script. So that's what you're downloading.

sh is a basic shell program that can parse and run this script, such as Dash or the Bourne shell.

The | character pipes the output from the command on the left to the input of the command on the right. So curl ... | sh means "Download this text and run it". Although this is a somewhat common pattern for complex installers, it's technically a form of remote code execution, and can be risky. Be sure you trust the source before routing arbitrary content from the internet into sh, bash, python, or other shells or programs that process commands on your local machine.


As you may have noticed, you could also just download the source code from https://sh.rustup.rs and run it directly:

cd ~/Downloads # or wherever you save it to
sh rustup-init.sh -y
dimo414
  • 170
  • sh is just a link pointing to currently configured system shell usually dash, think the short name for sh is POSIX shell. –  May 08 '20 at 04:20
  • Right you are, it's dash on Ubuntu. Fixed. – dimo414 May 08 '20 at 04:31
0

The | is a pipe. In your case, you need to uninstall your previously installed rust and install it again.