Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I avoid the need to create a temporary file to run two commands from a 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 run like this:

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

The -i parameter on cmd2 takes a filename. Is there a way I can do this in one line without creating the tmp.txt file?

like image 747
stand Avatar asked Dec 27 '22 11:12

stand


1 Answers

Try "process substitution" (that's what the Bash manual calls it)

cmd2 -i <(cmd1 p1 p2) p3

This also works the other way:

cmd2 -o >(cmd1 p1 p2) p3
like image 70
Martijn Avatar answered Jan 13 '23 13:01

Martijn