wget 的 -O - 起什么作用?

wget 的 -O - 起什么作用?

我看到一些 Linux 页面说明了如何安装密钥:

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

wget 中的“-O -”是什么?

这似乎与“添加-”有关。

这些是如何工作的?

谢谢〜

答案1

我用**来表示它很重要。来自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.

以及来自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 -.**

这解释了你的命令。

答案2

选项-O -将下载的文件打印到标准输出(而不是普通文件),-选项 inapt-key从标准输入读取。该命令相当于以下两个命令:

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

当您链接两个命令时,您不必费心保存文件,并且通常命令更短。

相关内容