I know this syntax
var=`myscript.sh`
or
var=$(myscript.sh)
Will capture the result (stdout) of myscript.sh into var. I could redirect stderr into stdout if I wanted to capture both. How to save each of them to separate variables?
My use case here is if the return code is nonzero I want to echo stderr and suppress otherwise. There may be other ways to do this but this approach seems it will work, if it’s actually possible.
There is no way to capture both without temp file.
You can capture stderr to variable and pass stdout to user screen (sample from here):
But there is no way to capture both stdout and stderr: