This is software engineering... Separate your dev environment from production and do a controlled deployment.
This is software engineering... Separate your dev environment from production and do a controlled deployment.
It comes as a surprise the first time you experience it that this rule doesn't follow with bash scripts.
Is bash closing the file and reopening it, or is the editor writing back to the same filehandle I wonder?
Until your script throws an exception, at which point your backtrace will not match the code that was running at all.
That's also true of executables, but bash scrips aren't exec'ed, they are just text files that are read in by the bash executable.
Delete and replace is different than edit in place. I don't know about Linux, but you can edit a binary on FreeBSD which is running, and it affects running copies (it's all memory mapped from the file), and that's why i use install instead of cp to update binaries (including shared libraries)
If you're writing a shell script for some mundane task on your personal machine, knowing the possible effects of editing a running script is useful knowledge, especially when something might behave in a non-intuitive way.
This is not an unusual thing to do in other situations. I'm sure you change your code all the time while an instance of the program is running, no matter whether it's compiled or interpreted. At least I don't habitually close a stop program first before I make changes to the source code.
The example in the article shows that that's a bad idea in bash scripts because they, unlike other code, don't get read in entirely (as in, say, Python, Perl, etc.) before they get executed.
That's why I get always hit by this shell problem. Happens every other week. There's not even a lock, as I would expect.
Which is probably not a good idea in the first place.