2014-02-25 65 views
0

我已經通過xargs的手冊頁讀了十幾遍,我仍然無法弄清楚如何讓它終止。當我在shell中調用它時:xargs echo this is xargs 我只在按ctrl + d時纔看到輸出。沒有辦法指定我希望xargs在讀取一定數量的參數後停止?所以,當我輸入xargs echo this is xargs並按回車,我立即看到this is xargs而不必按ctrl + d?Unix:Xargs不會終止

我已經嘗試設置與-e和-E和EOF標誌既不當這樣做這樣的工作對我來說:

xargs -Ez echo this is xargs z

我這麼問是因爲我試圖寫一個C這個程序會讓一個孩子分叉並使用execl來調用xargs,但是我的程序掛起了,所以在我嘗試繼續編寫程序之前,我想至少能夠從命令行調用xargs。

+1

你必須通過一個pipe.'echo這是xargs的將數據提供給'xargs' | xargs echo'可能工作。更多以示例方式使用xargs的示例調用可能是'find'。 -print | xargs stat'。祝你好運。 – shellter

回答

1

xargs的執行工具/命令,一旦它得到了從標準輸入文件輸入。

當你試圖執行xargs的echo something something其等待來自標準輸入文件的輸入,一旦你按下CTR + d這意味着EOF,xargs的與所述參數從標準輸入文件執行的命令。

下面是例子。

bash-$ echo "Testing xargs command" | xargs echo 
# echo executes by reading the input 
#file from pipe (which redirects first commands output into second commands input) 
Testing xargs command #output 
bash-$ 
bash-$ 
bash-$ xargs echo #waits until CTRL+D is pressed 
Testing xargs command 
Testing xargs command #output 
bash-$ 
bash-$ 
bash-$ xargs -E EOF echo # xargs option -E specifies End-OF-File-String, here EOF 
Testing xargs command 
EOF 
Testing xargs command #output 

希望這有助於

0

xargs從標準輸入讀取輸入,然後將其附加到傳遞給它的參數。你看到的是,當你運行xargs它正在等待來自stdin(顯然掛起)的輸入,當你鍵入ctl + d - 這是EOF到stdin,因此xargs處理它所讀取的所有內容。

xargsgrep在名爲*所有文件串「串」的一個例子的.conf

find . -name \*.conf -print | xargs grep string