2016-12-05 62 views
-3

我看到了一些「減」(即:「 - 」)上的一些的bash命令參數,難道他們是什麼意思?bash參數中的[ - ]是什麼?

這裏例如有2個:

一個wget -q -O - http,一個用於tar -xzf - -C

wget -q -O - http://apache.mirrors.pair.com/zookeeper/zookeeper-3.4.9/zookeeper-3.4.9.tar.gz | tar -xzf - -C /opt2 
+1

當你孤單看到一個連字符,它一般是指'stdin'或'stdout'。在你的'wget'例子的情況下,命令告訴'wget'發送其輸出('-O')悄然標準輸出('-q'),並在你的'tar'命令的情況下,你會使用stdin作爲從tar中提取('-x')壓縮('-z')內容到某個目錄('-C')的文件('-f')。請注意,這是一個常見的用法問題,而不是編程問題,所以我已經投票決定關閉它。您可能想要自己刪除它以避免進一步降價。 – ghoti

回答

3

這是許多程序遵循的約定。 -通常是指stdinstdout

嘗試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 -.) 

因此,如果使用-,文件將被打印到標準輸出。