Command Line – Piping File to a Command Without Piping Support

bashcommand linepipezsh

$ cat foo
foo
bar

Now if I do:

$ some_program foo

It's working.

But if I try:

$ cat foo | some_program

It's not working.

I'm looking for a clean way to pipe input to some_program without having to use messy temporary files.

Best Answer

Piping will put cat foo's stdout to some_program's stdin. In this case some_program is expecting an argument, not stdin, so you'll want to store cat foo's result into a variable and then call some_program $variable.

I'm not too sure on bash scripting, but try this?

bar=`cat foo`
some_program $bar

Actually, maybe this will work...

some_program `cat foo`
Related Question