7

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!

Dennis Williamson
  • 346,391
  • 90
  • 374
  • 439
r2b2
  • 1,255
  • 5
  • 13
  • 34
  • See also https://stackoverflow.com/questions/23361329/how-to-use-the-output-of-a-command-as-an-input-to-other-program-in-linux which is a really basic question about pipes. – tripleee Mar 25 '22 at 10:59

4 Answers4

12
/usr/bin/php /var/www/bims/index.php "projects/output" | xargs rm
Victor Sorokin
  • 11,878
  • 2
  • 35
  • 51
4

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 torm`.

Felix
  • 88,392
  • 43
  • 149
  • 167
3

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
  • 327,991
  • 56
  • 259
  • 343
0

I guess this could help>>

grep -n "searchstring" filename | awk 'BEGIN { FS = " " };{print $1}'

TestBud
  • 69
  • 1
  • 13