tags:

views:

36

answers:

4

I have a file like this.

rm a.txt
mkdir foo
cp a.doc docs

I am used to xargs but following command is not doing anything.

cat commands.txt | xargs -l1
A: 

Erm :

$ mv commands.txt commands.sh

$ chmod +x command.sh

$ ./command.sh

LenW
+2  A: 

you are doing it wrong! if your file is all shell commands, treat it as a shell script.

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

then on command line , chmod u+x commands.txt

./commands.txt

the "defacto" naming convention for shell script ends with extension .sh, although it can be anything. So try to name your script as ".sh" extension

ghostdog74
or `sh commands.txt`
hasen j
A: 

If you don't need to make it executable, source it in your current shell:

bash/ksh/...: . commands.txt

csh/...: source commands.txt

glenn jackman
A: 

If you commands are not in a file but the output from a program you may do use GNU Parallel http://www.gnu.org/software/parallel/:

cat commands.txt | parallel -j1

If the commands can be run in parallel (i.e. do not depend on eachother to complete) you can even do:

cat commands.txt | parallel
Ole Tange