[Top][All Lists]

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

History of bash's support for self-modifying shell scripts?

From: Josh Triplett
Subject: History of bash's support for self-modifying shell scripts?
Date: Sun, 9 Sep 2018 22:25:46 -0700
User-agent: Mutt/1.10.1 (2018-07-13)

While digging into the details of how bash reads shell scripts, I found
some indications that bash goes out of its way to support self-modifying
shell scripts. As far as I can tell, after reading and executing each
command, bash will seek backward and re-read the script from the
byte after the end of that command, rather than executing out of
buffered data previously read from the file. (For the purposes of this
logic, compound commands get run as a single unit, and this logic kicks
in after running the full compound command.)

I haven't found any indications that POSIX or similar require this, and
other shells like dash don't have the same behavior. I also haven't
found any details about this in the bash changelog or version control

I'd like to get some more information on the history of this mechanism,
if possible. What led to bash adding support for this? What version of
bash first incorporated this, and has it changed over time?

(I don't want to use this mechanism myself; I'm asking because I'm
working on a project that needs to care about various shells'
compatibility requirements, and I wanted to find out more about this
unusual corner case.)

Josh Triplett

reply via email to

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