Home > database >  Print stdout to terminal and use for another command as stdin
Print stdout to terminal and use for another command as stdin

Time:03-19

I want to make the stdout of a command visible on the terminal but also use it as stdin for another command without many workarounds i.e. creating files in between.

This obviously doesn't print the stdout to the terminal.

command1 > command2

With tee I would need to create a file in between, are there any other ways?

CodePudding user response:

So redirect a command to a file that outputs to the terminal.

command1 | tee /dev/stderr | command2

command1 | tee /dev/tty | command2

exec 3>&1
command1 | tee >(cat >&3) | command2
command1 | tee /dev/fd/3 | command2

{ command1 | tee /dev/fd/3 | command2; } 3>&1

etc. I typically use tee /dev/stderr to debug pipelines.

CodePudding user response:

Assuming you want to print the output of command1 on the screen, please try:

command1 | tee >(command2)

which distributes the output of command1 to both the terminal and the stdin for command2.

  •  Tags:  
  • bash
  • Related