bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: The 'source x' command doesn't keep variables set by x when source o


From: Greg Wooledge
Subject: Re: The 'source x' command doesn't keep variables set by x when source output is piped into other command
Date: Wed, 13 Nov 2024 18:44:04 -0500

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

[Prev in Thread] Current Thread [Next in Thread]