[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: |
Martin D Kealey |
Subject: |
Re: variable set in exec'ing shell cannot be unset by child shell |
Date: |
Sun, 15 Oct 2023 14:24:42 +1000 |
On Sun, 15 Oct 2023, 03:05 Greg Wooledge, <greg@wooledge.org> wrote:
> On Sat, Oct 14, 2023 at 12:55:21PM -0400, Ti Strga wrote:
> > it's just the "[[ -v foo ]]" tests to see where along the cloning
> process we are.
>
> *Shudder*
>
Likewise, brrrr.
If the *real* goal is to overwrite a running script with a new version of
> itself, and then re-exec it, then the correct solution is to wrap the
> script in a single compound command so that it gets read and parsed up
> front, before beginning execution of the main loop. Either wrap the whole
> thing in "{" ... "}" as Grisha suggested, or wrap the whole thing in a
> "main()" function and then call main "$@".
>
Agreed. Either way, don't forget to put "exit;" just before the closing
"}". Or write « exec main "$@" ».
(For good measure I would also make sure it's a valid posix text file with
a terminal newline, so that cat rubbish >> script can't break it.)
Personally I don't much care for the main "$@" style as it makes an extra
copy of argv for no particularly good reason, and Shell Is Not C™; but it's
better than allowing the script to blow up with parse errors after it's
started running.
-Martin
>
- Re: variable set in exec'ing shell cannot be unset by child shell, (continued)
- Re: variable set in exec'ing shell cannot be unset by child shell, Greg Wooledge, 2023/10/13
- Re: variable set in exec'ing shell cannot be unset by child shell, Robert Elz, 2023/10/13
- Re: variable set in exec'ing shell cannot be unset by child shell, Robert Elz, 2023/10/14
- Re: variable set in exec'ing shell cannot be unset by child shell, Martin D Kealey, 2023/10/15
- Re: variable set in exec'ing shell cannot be unset by child shell, Chet Ramey, 2023/10/16
Re: variable set in exec'ing shell cannot be unset by child shell, Chet Ramey, 2023/10/13
Re: variable set in exec'ing shell cannot be unset by child shell, Grisha Levit, 2023/10/13
Re: variable set in exec'ing shell cannot be unset by child shell, Kerin Millar, 2023/10/13