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?

  • 2
    Why the downvote? Appart from "what do curl do" (OP could easily figure out by himself), I think this is a valid question. I rather think it's very good if beginners want to know what they are copy-pasting from the internet, and we should not discourage that by downvoting.
    – pLumo
    Jan 9, 2019 at 17:10
  • 2
    @RoVo I didn't downvote, but the tooltip for the downvote says "This question does not show any research effort; it is unclear or not useful", and this question doesn't show any research effort.
    – wjandrea
    Jan 9, 2019 at 18:47
  • @wjandrea lol that's partly true but the sh -c command still was quite tough to understand don't you find? When you understand nothing that's hard to understand any part you know.
    – UgaUga
    Jan 9, 2019 at 18:56
  • 1
  • sh man were pretty long, so am I a gambler
    – UgaUga
    Jan 9, 2019 at 19:01

3 Answers 3

$ 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.



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.


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.
  • 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 9, 2019 at 17:41

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.