Take care editing bash scripts (2019)
Whether this happens or not depends on how the file is edited, I think.  From the strace output shown in TFA, it appears the file is not opened again between executing the lines.  E.g. using vim as editor, the modified file is actually written as a new file under the same filename.  In Linux, the bash process will keep the original file open so that the inodes are not reclaimed by the filesystem until the file is closed.  Hence the bash process won&#x27;t &quot;see&quot; the modified script file.<p>I&#x27;ve tested this, and indeed when editing the file with vim, I can&#x27;t reproduce the &quot;dangerous&quot; behavior.  To trigger this behavior, I&#x27;d have to <i>overwrite</i> the script file, e.g. by<p><pre><code>    1. create script run.sh with &quot;sleep 30&quot; etc
    2. create script run1.sh with &quot;sleep 3&quot; instead
    3. start run.sh
    4. overwrite script: cat run1.sh &gt; run.sh
    5. after the sleep, the commented line does execute
</code></pre>
Are there editors that actually overwrite the original file, instead of creating a new file?  I thought the latter is the recommended approach as it can prevent data loss e.g. if there&#x27;s a crash during writing the file.<p>P.S. If the script in question is on a network file system, things may be different even for vim. E.g. on NFS the file handle doesn&#x27;t behave fully like a regular POSIX file handle, and the NFS server might actually reopen the file between reads, thus delivering the modified contents to the bash process.