23

I intended to download nvm from https://github.com/creationix/nvm when I stumbled upon the following command:

curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.32.1/install.sh | bash

Does anyone know the meaning of the dash behind -o? It isn't mentioned in the man pages, nor could I find any clue. I also tried it without the -o-option and it still works, which is why I'm wondering what it could mean?

eol
  • 23,236
  • 5
  • 46
  • 64
  • Same meaning as a dash has in `cat -` or other standard/conventional cases where a filename would otherwise be expected. – Charles Duffy Jan 05 '23 at 19:46

1 Answers1

22

curl's -o option gives you the ability to specify an output file. - in this context refers to the standard output(stdout), which means curl will output its response to the the standard output plugged as standard input to the bash invocation.

In this context it could have been omitted as outputting to stdout is curl's standard behavior.

As chepner mentions, it can become useful when you're downloading multiple ressources at the same time and want to display only one of them on stdout :

curl -o- -o fileA -o fileB url1 url2 url3

In this case url1 will be output to stdout, url2 to fileA and url3 to fileB.

Note that this could still be avoided since ressources without a matching output specification will be output to stdout. The following command would behave the same as the previous one :

curl -o fileA -o fileB url2 url3 url1
Community
  • 1
  • 1
Aaron
  • 24,009
  • 2
  • 33
  • 57
  • 1
    Since `-o` can be used once per URL, it might be useful as a way to write some URLs to files, and others to standard output: `curl -o url1.html -o - -o url3.html "$URL1" "$URL2" "$URL3"`. – chepner Nov 09 '16 at 15:26
  • @chepner thanks, I thought I had once used that for a good reason but couldn't remember how. – Aaron Nov 09 '16 at 16:00