tags:

views:

74

answers:

3

So I call this PHP script from the command line:

/usr/bin/php /var/www/bims/index.php "projects/output"

and its output is:

file1 file2 file3

What I would like to do is get this output and feed to the "rm" command but I think im not doing it right:

/usr/bin/php /var/www/bims/index.php "projects/output" | rm 

My goal is to delete whatever file names the PHP script outputs. What should be the proper way to do this?

Thanks!

+5  A: 
/usr/bin/php /var/www/bims/index.php "projects/output" | xargs rm
Victor Sorokin
that worked! what is xargs command about? thanks!
r2b2
man xargs: "xargs - build and execute command lines from standard input". You should read that manual page ;)
Victor Sorokin
+2  A: 

you can try xargs

/usr/bin/php /var/www/bims/index.php "projects/output" | xargs rm 

or just simply use a loop

/usr/bin/php /var/www/bims/index.php "projects/output" | while read -r out
do
  rm $out
done
ghostdog74
+2  A: 

Simplest solution:

rm `/usr/bin/php /var/www/bims/index.php "projects/output"`

What is between the backticks (`) is run and the output is passed as argument to rm.

Felix
xargs is slightly better: it can handle output that is too long for the maximum command line length by running `rm` more than once.
Harold L
I didn't say *better*. I said *simple* :).
Felix
note: might not work if the Php script produce files with spaces
ghostdog74