0

In this command:

wget -qO- https://get.speedify.com | bash -

Source: https://support.speedify.com/article/562-install-speedify-linux

...the first -q is the option for "quiet" mode. What is the O- (notice that is the letter "O", NOT a zero) part though? Why the letter O? Why the trailing -? Finally, after the bash command there is also a trailing -. Why?

Update: now that I know that is the letter O, NOT a zero, I see this from the man wget manual pages:

  -O file
  --output-document=file
      The documents will not be written to the appropriate
      files, but all will be concatenated together and written
      to file.  If - is used as file, documents will be
      printed to standard output, disabling link conversion.

So, -qO is the same as -q -O, and -O sets the output file, and -O- apparently says to print the document to standard output. I wonder why they didn't do -O=- or -O - though...?

Not a duplicate:

This question answers the smallest, least-relevant, and least-significant part of my question: Do command line options take an equals sign between option name and value?. It does not answer my question.

2
  • - is stadin/stdout Here is a deeper answer. unix.stackexchange.com/questions/16357/…
    – threeiem
    Sep 14, 2021 at 22:56
  • I actually wondered why that commands lacks a sudo before bash (without sudo, you can't be sure you achieve the maximum of damage possible when blindly running commands off the internet). But no problem, it's all there on the linked page ;-)
    – user313992
    Sep 16, 2021 at 21:16

1 Answer 1

4

I believe there are 3 questions you are looking for answers about. Let me take them in turn.

  1. As you identified from the man page, the - when used as the filename to write to will indicate stdout.

  2. In the bash portion of the command, the - is used as the name of the file to read from. In this case, it tells it to read from stdin. Since the two commands are piped together, it will be reading what is being written to stdout from step 1.

  3. Finally, the reason that it isn't -O=- is because of the way getopt from the standard C library works when parsing command line options. When you have single letter option that take no parameters (e.g., -v for verbose and -r for recursive) you can specify them individually (-v -r) or as a block (-vr) and you use only a single dash before them. If a single letter option takes a parameter (e.g., -w <outfile>) then getopt expects the next thing after the option to be parameter. So -w foo and -wfoo are the same in that they write to the file foo. However, -vw foo and -wv foo would be interpreted differently. -vw foo would be verbose and write to the file foo, but -wv foo would write to the file v and have foo as an additional command line argument.

Long arguments are specified by two dashes at the start. When processing those arguments, it expects the parameter to be after an = sign. If you look back at the quoted section from wget, you see that it tells you -O file for the "short" version of the option and --output-documet=file for the long version.

2
  • What about -O - (having the space after the O and before the final -)? Is that valid? Why or why not? Sep 16, 2021 at 20:35
  • @GabrielStaples try it. It's valid all right.
    – ilkkachu
    Sep 16, 2021 at 20:50

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .