What's the function of wget's -O -?

9,513

Solution 1

The option -O - prints the downloaded file to standard output (instead of a ordinary file) and the - option in apt-key reads from standard input. The command is equivalent to the two commands:

wget http://packages.ros.org/ros.key
sudo apt-key add ros.key

When you chain both commands you don't have to bother with saving a file and usually the command is shorter.

Solution 2

I used ** to indicate it is important. from man wget

-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 -.) **

       Use of -O is not intended to mean simply "use the name file instead
       of the one in the URL;" rather, it is analogous to shell
       redirection: wget -O file http://foo is intended to work like wget
       -O - http://foo > file; file will be truncated immediately, and all
       downloaded content will be written there.

and from man apt-key

add filename
       Add a new key to the list of trusted keys. The key is read from
       filename, or ** standard input if filename is -.**

this explains your command.

Share:
9,513

Related videos on Youtube

keviveks
Author by

keviveks

I love Linux & Opensource!!

Updated on September 18, 2022

Comments

  • keviveks
    keviveks over 1 year

    I see some linux page says how to install the key:

      wget http://packages.ros.org/ros.key -O - | sudo apt-key add -
    

    What is "-O -" in wget?

    It seems related with "add -".

    How these works?

    Thank you~