On Wed, Nov 13, 2024 at 15:18:58 -0800, Yuri wrote:
> I need to (1) source the user script, (2) save this script's output to a
> dedicated file, (3) keep the same output in stdout, and (4) keep environment
> variables that the user script sets for later commands.

If the "user script" runs quickly enough, then:

    source userscript >logfile 2>&1
    cat logfile

If the user script take a long time to run, and you need the output
in the terminal in real time, then there isn't any simple answer I'm
aware of.  You're going to be looking at variants of:

    exec 3> >(tee logfile)
    source userscript >&3 2>&3
    exec 3>&-

There will be visible "cracks" in all of these, if you look hard enough
for them.  But maybe they'll be good enough for your purposes.

Reply via email to