🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.unix.shell
Article #225

Re: Back To CS Basics. Fuck AI

#225
From: Kaz Kylheku
Date: Tue, 20 Oct 2026 17:38
37 lines
3357 bytes
On 2026-10-20, Carlos E.R. <robin_listas@es.invalid> wrote:
> I have learned not to edit a script while it was running, weird things 
> happened when I did. My theory was that bash kept an index pointing to 
> the current line. Dunno if as byte or as line.

IIRC, here is how it works: bash reads the script via a buffered stream
as it executes, thus some multi-kilobyte blocks of the script text. If
you overwrite the script while it is running, it will not affect the
script text that is already waiting in the buffer, but when bash
reads to the end of the buffer, after that it will read the altered
script. Therefore it is somewhat "unpredictable" where the discontinuity
will occur: you have to know the buffer sizes and relate them to the
script text.

Earlier parts of the script are not re-read.  Bash does not re-read code
to iterate over a loop; the whole top-level command is parsed into an
internal representation that is executed.  If a script modifies its own
source file, everything before and including that modifying command is
"safe".

There may be some subtleties with here docs.  Suppose have
a command ending in <<WORD followed by a large amount of here-doc
data terminated by WORD. I don't know whether Bash reads all of it,
or under what conditions. Probably when Bash runs on a system where
here docs have to be done using temprary files, it does have to read
all the data, put it into the temporary file and then launch the command
with the <<WORD syntax replaced by the name of the temporary file.

But on a system where the program can be given a /dev/fd/<n> syntax or
whatever to refer to a file descriptor, bash can pipe the data to it.
Maybe it is possible for the script to be modified after that command is
launchedm such that the command receives  different here doc data.

-- 
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
Technical Details
Message-ID: <20261020081822.527@kylheku.com>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
References: <18dee4b6cab427fa$865$2574533$802601b3@news.usenetexpress.com> <POycnb0WPpTmPEz3nZ2dnZfqn_ednZ2d@giganews.com> <87ik32455m.fsf@solcaium.us> <6ad33478$0$28048$426a74cc@news.free.fr> <11b0ms8$iems$8@dont-email.me> <11b0pbe$3pvda$2@dont-email.me> <871p9lv3z2.fsf@safunu.org> <1rmjqmx0ds.ln2@Telcontar.valinor>

Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!usenet.blueworldhosting.com!diablo1.usenet.blueworldhosting.com!eternal-september.org!feeder.eternal-september.org!nntp.eternal-september.org!.POSTED!not-for-mail
From: Kaz Kylheku <046-301-5902@kylheku.com>
Newsgroups: comp.unix.shell
Subject: Re: Back To CS Basics. Fuck AI
Date: Tue, 20 Oct 2026 17:38:24 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 37
Message-ID: <20261020081822.527@kylheku.com>
References: <18dee4b6cab427fa$865$2574533$802601b3@news.usenetexpress.com>
 <POycnb0WPpTmPEz3nZ2dnZfqn_ednZ2d@giganews.com>
 <87ik32455m.fsf@solcaium.us> <6ad33478$0$28048$426a74cc@news.free.fr>
 <11b0ms8$iems$8@dont-email.me> <11b0pbe$3pvda$2@dont-email.me>
 <871p9lv3z2.fsf@safunu.org> <1rmjqmx0ds.ln2@Telcontar.valinor>
Injection-Date: Tue, 20 Oct 2026 17:38:28 +0000 (UTC)
Injection-Info: dont-email.me;
	logging-data="3404552"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX19yhZLKJN5cLFfarNfI5p40FY2O6qDvWW4="; posting-host="b8fc923f0fe78939cedc2970bc5ec330"
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:DY+k46zDsQirp7+4XUpWEx963t0= sha256:pgi3tmDwpyTVywnbyF4rhvJXgUW2LkL58TQN4/KG3rc=
	sha1:7TsB5ujiJ07+yxW03puuX7suW7c= sha256:d/ogeFpX3Xlszfiv14owOotgE9Ll9tb0fN6SXEZ9/3o=