I've been wandering in the web and saw this about how to install atom, the new text editor:
$ curl -sL | sudo apt-key add -
$ sudo sh -c 'echo "deb [arch=amd64] any main" > /etc/apt/sources.list.d/atom.list'I just wanted to know what these commands are actually doing. What does curl do ?
I also read sh was about running some shell instance but for what, what does this command make possible for instance, and what does it do specifically here?
3 Answers
$ curl -sL | sudo apt-key add -This is actually two commands.
curl -sL downloads the GPG key from PackageCLoud for the Atom Editor repository.
sudo apt-key add - adds it to apt so it can recognize and validate the repository's GPG signatures on packages.
$ sudo sh -c 'echo "deb [arch=amd64] any main" > /etc/apt/sources.list.d/atom.list'Easier if we split it into its three constituent parts.
sudo executes the sh command as superuser.
sh -c indicates to execute a specific command in the sh shell.
'echo "deb [arch=amd64] any main" > /etc/apt/sources.list.d/atom.list' is the command being run by sh -c which creates the separate repository entry in /etc/apt/sources.list.d/atom.list so that when you do sudo apt update it'll check that repository for package data.
CURL
Like the homepage says, curl is a
command line tool and library for transferring data with URLs
Greatly simplyfing, it allows you to download a file from a (web)server.
You could get the same result by opening with a browser and then saving the displayed file to disk.
SH
Running sh opens a new shell. The way it's used here is to execute a list of commands (via the -c flag) in a new shell with root privileges (the sudo part).
The sh -c part is needed because of the redirection (> /etc/apt/sources.list.d/atom.list). As the file /etc/apt/sources.list.d/atom.list needs root privileges to be written to, you cannot simply do sudo echo ... > file, as the redirection doesn't "inherit" privileges from the sudo part. You have to wrap the whole echo + > it in a new shell instance. It's somewhat equivalent to these separate steps:
sudo shto open a new shell with root privileges;echo "deb [arch=amd64] any main" > /etc/apt/sources.list.d/atom.listto write the new line to theatom.listfile;exitto go back to your normal user shell.
For the beginers:
sh (shell) is a command interpreter program. Like Bash "Bourne Again SHell" is the GNU Project's shell.
curl or cURL is a computer software project providing a library and command-line tool for transferring data using various protocols. The cURL project produces two products, libcurl and cURL. It was first released in 1997. The name stands for "Client URL".