0
votes

I need to take the output from one command, tee it into two different commands and save their output in variables.

So something like this:

command1 | tee >(command2 > var1) >(command3 > var2) >/dev/null

Where var1 and var2 are variables not files.

If there's another way to direct the output of a command into two different commands without using tee, I'm open to that as well. I know I can simply store the output of command1 into a variable and then echo it into command2 and command3 but I don't want to do that.

1

1 Answers

1
votes

Because of this (found in bash reference manual):

Command substitution, commands grouped with parentheses, and asynchronous commands are invoked in a subshell environment [...]

you cannot pull the variables out of the subshells:

Changes made to the subshell environment cannot affect the shell’s execution environment.

You will have to use a variable to store the first output and pass it to the other commands.