Editing a running Bash script in place can crash or misexecute it
A developer reported that adding a comment to a shell script that was actively running caused a sixteen-minute job to fail with a syntax error. Bash keeps a byte offset into the open file rather than a line number, so changing the file mid-execution makes it resume at the wrong position. A simple demonstration showed a stray command running and a line executing a second time. The fix is to write a new version to a temporary file in the same folder and rename it over the original, since a running process holds the old file by its inode. In-place write methods such as shell redirects are the ones that cause this problem.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in