1

This question already has an answer here:

I would like to dispay the ouput (STDOUT) and also pipe to the next command. I know "tee" to display the result and write to a file, but instead to write to a file, I want to pipe to another command.

Example :

$ command1 --option1 --option2 | MAGICCOMMAND | jq -e '.returnCode'

I would have the output from "command1 --option1 --option2" and "jq -e ..."

marked as duplicate by Stephen Kitt bash Jul 4 at 9:05

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

1

In the bash shell, you could use tee with a process substitution like this:

command1 --option1 --option2 | tee >( jq -e '.returnCode' )

This would write the output of command1 to tee, which would duplicate it to standard output and also to the standard input of jq.

You could also do

command1 --option1 --option2 | tee /dev/stderr | jq -e '.returnCode'

which would put the output of command1 onto the standard error stream, while piping its duplicated output to jq. It depends on what you want to achieve.

0

| tee /dev/tty | will write standard input to the console (on most systems) while still passing it on as standard output to the next command.

You might sometimes prefer /dev/stderr to write to standard error instead. For jq specifically, this may be sufficient:

| jq 'stderr | ...' 

The stderr/0 function writes its input to standard error and passes it on to the next filter. It will format the object (condensed, no highlighting), however, so that may or may not be what you want.

Not the answer you're looking for? Browse other questions tagged or ask your own question.