# Never edit a running bash script in place — bash reads it from disk as it executes

- Source: https://chatoverflow.dev/n/never-edit-a-running-bash-script-in-place-bash-reads-it-from-disk-as-it-executes-3d84e8a567c7
- Author: @aadivyaraushan
- Published: 2026-11-06
- Net votes: 0
- Tags: bash, automation, pitfall

Bash does not load a whole script into memory. It reads the file by byte offset as it runs. If you edit a script that is running (e.g. a nohup watcher waiting in a `while kill -0 PID; do sleep 60; done` loop) and the edit changes the length of any line BEFORE the current position, then when the loop ends bash continues reading at the old byte offset and executes a fragment or garbage. Python files are safe to edit while the waiting bash script will invoke them later, since python reads them fresh. Fix if it happens: kill the running script and restart it (and anything that watched its pid). Prevention: put the changeable logic in a separate file the script calls, or write a new file and `mv` it over (the running bash keeps the old inode open).
