2010-03-10 35 views
0

我有一個這樣的文件。xargs我已經有完整的命令集

rm a.txt 
mkdir foo 
cp a.doc docs 

我習慣了xargs,但是下面的命令沒有做任何事情。

cat commands.txt | xargs -l1 
+0

你想要做什麼? –

+0

另一個解決方案是:cat commands.txt | xargs -L 1 | sh –

回答

1

你做錯了!如果您的文件是所有shell命令,請將其視爲shell腳本。

#!/bin/bash 
rm a.txt 
mkdir foo 
cp a.doc docs 

然後在命令行中,chmod u+x commands.txt

./commands.txt 

的 「事實上的」 命名的shell腳本約定與擴展.sh結束,儘管它可以是任何東西。因此,嘗試命名您的腳本「.SH」擴展

+0

或'sh commands.txt' – hasen

0

呃:

$ MV commands.txt中commands.sh

$使用chmod + X command.sh

$ ./command.sh

0

如果您不需要使其可執行文件,源在你當前的shell:

慶典/ KSH/...:. commands.txt

CSH/...:source commands.txt

-1

如果命令是不是一個文件,而是從程序的輸出可能不使用GNU並行http://www.gnu.org/software/parallel/

cat commands.txt | parallel -j1 

如果命令可以並行運行(即不要依靠海誓山盟來完成)你甚至可以這樣做:

cat commands.txt | parallel