From:   Matt
Subject: [bug #68131] Shell script misbehaves when edited
Date:   Sun, 8 Mar 2026 12:42:13 -0400 (EDT)

>When a shell script is edited while running, it appears the current invocation
>takes the update right away. However, it seems to keep track of its position
>naively rather than based on any parsing of the script itself. Thus, if the
>modification changes the position of text across lines, this results in
>unexpected and potentially dangerous behavior.

It would be good to see an example case of this.

>If this is desired behavior (to allow editing in-flight scripts), please feel
>free to close. However, it seems to me it would be safer to copy the full
>shell script to a memory buffer when run, such that subsequent edits don't
>affect already-running invocations.

Although I have never really thoroughly tested this, it is something
that I often do - that is, I have a long-running script and I will
make changes to it w/o explicitly exiting the running version.  Of
course, you have to exit and re-start in order to pick up the changes,
but it is usually easier to defer the exit until after the edits, and
then do the exit/re-start at the same time.

Anyway, I've never had a problem with this, though I certainly assume
that nothing is guaranteed.  It has always seemed likely to me that
bash *does* do the right thing here - which would be to read the whole
file into memory at startup and then go from there - rather than being
dependent on the on-disk file (*).  But of course, there's no real way to
know other than to carefully examine the source code and/or have
someone in the know make a definitive statement.

In any case, I doubt it is a bug either way.  Again, I'd like to see
an actual instance of it being a problem (which you, the OP, seem to
have one of).

(*) Of course, there are some edge cases, such as if the script
sources (dots) another file (which might have been created on-the-fly).

=================================================================================
Please do not send me replies to my posts on the list.
I always read the replies via the web archive, so CC'ing to me is unnecessary.

When responding to my posts, please try to refrain from giving bureaucratic 
answers.
If you have nothing useful to say, then just click Next and go on.

Reply via email to