4

Option -O file is used to have wget output to a specific file.

Why does wget -O- "$url" output to stdout? There is no such expression -O- in man wget. Why does the second character - in -O- mean downloading the "$url" and outputting it to stdout?

PesaThe
  • 7,259
  • 1
  • 19
  • 43

2 Answers2

7

By posix standard, if a program takes a file path argument for output, - is used to mean "standard output". The man page describes this under -O.

erik258
  • 14,701
  • 2
  • 25
  • 31
  • 4
    If a single-letter option `-X` takes an argument, you can use either `-X arg` or `-Xarg`. That's absolutely standard. – melpomene Dec 19 '17 at 00:58
  • 3
    It's "standard" in the literal sense that it's standardized as part of the POSIX utility argument syntax guidelines -- see http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap12.html *[A] conforming implementation shall also permit applications to specify the option and option-argument in the same argument string without intervening blank characters*, that being the "except as noted" clause referred to by utility syntax guideline 6 (near the end of the same document). – Charles Duffy Dec 19 '17 at 01:02
  • 2
    Also, see Guideline 13 by the end of that same document -- meaning it's not just a "loose convention" that `-` refers to stdin or stdout, but likewise a POSIX mandate (albeit only a mandate applicable to POSIX-standardized utilities). – Charles Duffy Dec 19 '17 at 01:06
  • 1
    I stand corrected. So arguments with optional parameters _should_ omit the space. Options with required parameters (such as `-O` for wget) _should_ have a space but _must_ also work without it. Interesting, thanks for the correction. – erik258 Dec 19 '17 at 01:08
2

https://www.gnu.org/software/wget/manual/wget.html#Download-Options:

‘-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. (Use ‘./-’ to print to a file literally named ‘-’.)

Community
  • 1
  • 1
melpomene
  • 84,125
  • 8
  • 85
  • 148