I have a user-provided bash script that creates a directory in some way and outputs its path. It can work in many ways, for example, it can clone a git repository, do some setting up, and then output the path. Something like this:
git clone ...repo --quiet && echo "...path"
I run it using command substitution, wrapping with $(...) and using the resulting path. Something like this:
path=$(...)
The command itself is user-provided, so it can be anything, I can't anticipate it will always be git clone.
It works well, but if the commands before the final echo outputs anything, it will mess up the result. I could redirect stdout to stderr for all preceding commands and only use stdout at the last step, but I feel it's a hack.
Is there any way to leave stdout and stderr to the caller's stdout and stderr, but have a separate stream for the result?