bug-bash
[Top][All Lists]
Advanced

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

Re: variable set in exec'ing shell cannot be unset by child shell


From: Dale R. Worley
Subject: Re: variable set in exec'ing shell cannot be unset by child shell
Date: Fri, 13 Oct 2023 14:21:59 -0400

Ti Strga <wearyofallthiscrap@gmail.com> writes:
> The summary is that if a parameter is set specifically for a '.'/'source'
> command, and the source'd file calls 'exec' to run another script, then
> that exec'd script cannot unset the parameter; if we want that parameter
> to not be present in the exec'd script, then the source'd file must do
> the unsetting prior to exec.

I was too lazy to chew through your example, but I coded an instance of
your description (above), and it does not show the dubious behavior that
you report.  Specifically,

    $ bash -version
    GNU bash, version 5.1.0(1)-release (x86_64-redhat-linux-gnu)
    ...
    $ ls -l
    total 20
    -rwxr-xr-x. 1 worley worley 112 Oct 13 14:14 inner
    -rw-r--r--. 1 worley worley 113 Oct 13 14:13 middle
    -rw-r--r--. 1 worley worley 123 Oct 13 14:12 outer
    $ cat outer
    echo "Value in ./outer at the beginning: $OUTSIDE"

    OUTSIDE=xyzzy . ./middle

    echo "Value in ./outer at the end: $OUTSIDE"
    $ cat middle
    echo "Value in ./middle at the beginning: $OUTSIDE"

    exec ./inner

    echo "Value in ./middle at the end: $OUTSIDE"
    $ cat inner
    echo "Value in ./inner at the beginning: $OUTSIDE"

    unset OUTSIDE

    echo "Value in ./inner at the end: $OUTSIDE"
    $ bash ./outer
    Value in ./outer at the beginning: 
    Value in ./middle at the beginning: xyzzy
    Value in ./inner at the beginning: xyzzy
    Value in ./inner at the end: 
    $

Here, when I run the command "bash ./outer", the subshell executes the
critical command "OUTSIDE=xyzzy . ./middle".  The source'd script middle
then exec's inner.  But inner seems to be able to unset $OUTSIDE as one
expects.  (Of course, when inner finishes, the command I typed exits, as
executing inner replaced executing outer.

Dale



reply via email to

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