Is there a way to show the output of a command substitution, in color, while it is executing, while still storing it to a variable? This would mainly be for testing/debugging purposes, and the output would not be shown normally.
If I do this:
output=$(some_command)
if [ "$debug" ]; then
echo "$output"
fi
...then this is close, but not what I want in a few ways:
- Even if the command would have otherwise emitted output to the terminal in color, it's printed in black-and-white.
- The output is only shown after the command is finished, rather than streaming as it runs.
How can I conditionally stream output to a terminal without squelching color?