Use the output of the command as input to the next command

Therefore, I call this PHP script from the command line:

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

and its output:

 file1 file2 file3 

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

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

My goal is to remove all file names output to a PHP script. What should be the right way to do this?

Thanks!

+4
source share
4 answers
 /usr/bin/php /var/www/bims/index.php "projects/output" | xargs rm 
+8
source

you can try xargs

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

or just use a loop

 /usr/bin/php /var/www/bims/index.php "projects/output" | while read -r out do rm $out done 
+3
source

The simplest solution:

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

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

+2
source

I think this could help →

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

0
source

Source: https://habr.com/ru/post/1307639/


All Articles