1

I've been wandering in the web and saw this about how to install atom, the new text editor:

$ curl -sL https://packagecloud.io/AtomEditor/atom/gpgkey | sudo apt-key add -
$ sudo sh -c 'echo "deb [arch=amd64] https://packagecloud.io/AtomEditor/atom/any/ 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?

terdon
  • 100,812
UgaUga
  • 29

3 Answers3

4
$ curl -sL https://packagecloud.io/AtomEditor/atom/gpgkey | sudo apt-key add -

This is actually two commands.

curl -sL https://packagecloud.io/AtomEditor/atom/gpgkey 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] https://packagecloud.io/AtomEditor/atom/any/ 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] https://packagecloud.io/AtomEditor/atom/any/ 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.

Thomas Ward
  • 74,764
0

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 https://packagecloud.io/AtomEditor/atom/gpgkey 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:

  1. sudo sh to open a new shell with root privileges;
  2. echo "deb [arch=amd64] https://packagecloud.io/AtomEditor/atom/any/ any main" > /etc/apt/sources.list.d/atom.list to write the new line to the atom.list file;
  3. exit to go back to your normal user shell.
wjandrea
  • 14,236
  • 4
  • 48
  • 98
  • ok! so it runs another shell in order to override the redirection restriction of 'echo', now I understand more this kind of 'wrapping' and the reason we do this, that was unusual for me! thank you. =) – UgaUga Jan 09 '19 at 17:41
0

For the beginers:

  1. sh (shell) is a command interpreter program. Like Bash "Bourne Again SHell" is the GNU Project's shell.

  2. 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".

Vijay
  • 8,056