Janis Papanagnou <jani…@hotmail.com>:
> On 2026-10-17 22:47, Lawrence D’Oliveiro wrote: > I've just done this ("a script change while it's running") [*] > > [*] What I've done was to run the following script "dynchg.sh" > > while read ; do > echo $REPLY > done > > and change it (from another terminal) while it runs by > > sed -i '2p' dynchg.sh >
As the "-i" option is not defined by the POSIX standard but by GNU sed, I assume that your example uses GNU sed. GNU sed's "-i" option does not edit the file in place.  Rather it sends its output to a new file (instead of to standard output), then removes (or renames) the name of the original file.  Finally, the name of the new file is renamed to be the no more existing name of the original file. => GNU sed doesn't modify the original shell script, which has been opened by the shell. Therefore the shell won't see anything of the new file but rather stick to the already opened original file (even, if that original file hasn't got any file name).
> I could even remove that file from the directory and it still processes data as expected.
Yes.  As long as the shell doesn't close the file descriptor accessing the original file, it will continue to access the original unmodified file.