You can use yourmainscript 2>&1 | tee log
which will capture stdout and stderr from all imported/invoked scripts in yourmainscript
while also showing it on screen.
Inside yourmainscript
, you can get the same effect using:
echo "Redirecting the rest of script output to 'log'"
exec > >(tee log) 2>&1
rest of your code
To redirect just a certain section:
echo "Redirecting the next commands"
{
cmd1
cmd2
} > >(tee log) 2>&1
echo "Continuing as normal"