Bash – Pass a pipe to a command that expects a filename

bashcommandpipe

Say I have a command foo which takes a filename argument: foo myfile.txt. Annoyingly, foo doesn't read from standard input. Instead of an actual file, I'd like to pass it the result of another command (in reality, pv, which will cat the file and output a progress meter as a side effect).

Is there a way to make this happen? Nothing in my bag of tricks seems to do it.

(foo in this case is a PHP script which I believe processes the file sequentially).

I'm using Ubuntu and Bash

EDIT
Sorry for the slightly unclear problem description, but here's the answer that does what I want:

pv longfile.txt | foo /dev/stdin

Very obvious now that I see it.

Best Answer

If I understand what you want to do properly, you can do it with bash's command substitution feature:

foo <(somecommand | pv)

This does something similar to what the mkfifo-based answers suggest, except that bash handles the details for you (and it winds up passing something like /dev/fd/63 to the command, rather than a regular named pipe). You might also be able to do it even more directly like this:

somecommand | pv | foo /dev/stdin