Score:0

Editing a shell file while running it affects its behavior?

cn flag

I am using the bash shell. Today talking with a colleague, he told me something that I found surprising and I would like to confirm it.

Say I have a shell script like this

#!/bin/bash

set -eu

python some_really_long_script.py

So I start executing it by running ./the_shell_script.sh.

Now, the command takes time. Probably hours.

My question is, if I edit this script file like this

#!/bin/bash

set -eu

python some_really_long_script.py

python some_other_really_long_script.py

and I save it, will the next command be executed after the first one?

I thought that the script was read to memory and executed so editing would have no impact but I was told this is possible.

EDIT1 I am calling my sh from a container with these details

cat /etc/os-release 
NAME="Ubuntu"
VERSION="20.04.4 LTS (Focal Fossa)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 20.04.4 LTS"
VERSION_ID="20.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=focal
UBUNTU_CODENAME=focal

I checked and outside the container the release is different

guiverc avatar
cn flag
You haven't provided any OS/product/release details; but in my own usage I've found the running scripts do not notice later edits (*during execution*) as the scripts are usually small & thus cached in buffers used by the running shell, thus no need to re-read from files (where inodes for file contents may have changed anyway)
cn flag
since this is an ubuntu forum, I assumed linux is assumed. I also have always assumed the script is read in memory so not reread after edit, but my colleague said it is possible Therefore my question
guiverc avatar
cn flag
https://ubuntuforums.org/ is the site of Ubuntu Forums, this is a Ubuntu Q&A site; and I do consider the OS/release, even Ubuntu product matters. I too believe as your friend that's its possible for changes to be impacted during operation (I've experienced it myself & actually used it to advantage in the past), but the product/release plus of course **shell** being used impact the defaults & expected results; you tagged *bash* which by default does not re-read the files as in desktop releases I've largely used. *Also don't forget your scripts maybe running in `dash` and not `bash`*
guiverc avatar
cn flag
More FYI: Release matters as things change over time... the script I mentioned that relied on *changing itself* to impact results worked on one release, but not a much later release. Our systems change over time, esp. the defaults & releases whilst an imperfect way of indicating what we're actually using, are the best we have. Ubuntu systems install with one default for a given release; which may have differed to prior releases, thus there can be differences between a *release-upgraded* system and a *fresh* install, but as stated the release is our *best* way to easily show info
cn flag
I added the release details
I sit in a Tesla and translated this thread with Ai:

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.