How to avoid the need to create a temporary file to run two commands from the bash shell?

I need to run two commands. The first creates a file that is used as an input parameter to the second. I can work as follows:

$ cmd1 p1 p2 > tmp.txt $ cmd2 -i tmp.txt p3 

The -i cmd2 on cmd2 accepts the file name. Is there a way to do this on a single line without creating a tmp.txt file?

+4
source share
2 answers

Try "process overriding" (this is what Bash calls it)

 cmd2 -i <(cmd1 p1 p2) p3 

This also works differently:

 cmd2 -o >(cmd1 p1 p2) p3 
+11
source
 cmd1 p1 p2|xargs cmd2 p3 -i 

cmd2 will invoke cmd2 and turn its own stdin (cmd1 output) into command line arguments for cmd2.

-1
source

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


All Articles