I'm trying to do something like this:
- save command1 output to file
- feed same output to command2
something like this
command2 $(command1 > file.txt)
but that didn't work.
I'm trying to do something like this:
something like this
command2 $(command1 > file.txt)
but that didn't work.
Use tee. This copies its standard input to a file and also its standard output. Then pipe the output to the second command.
command1 | tee file.txt | command2
Your question used
command2 $(command1 > file.txt)
tee pipes are great, but if I read this right, command2 expects a filename?
If so, maybe you can use
command2 <( command1 )
If you also need the file, then tee inside the construct -
command2 <( command1 | tee file.txt )
If for some strange reason it absolutely requires a file NAME (can't really imagine why), then you could always try this as a last resort -
command2 "$( command1 > file.txt && echo file.txt )"