Revision: 866
http://svn.savannah.gnu.org/viewvc/?view=rev&root=administration&revision=866
Author: iank
Date: 2026-04-14 07:42:03 -0400 (Tue, 14 Apr 2026)
Log Message:
-----------
bash style guide, add gotcha
Modified Paths:
--------------
trunk/sviki/fsf/bash-style-guide.mdwn
Modified: trunk/sviki/fsf/bash-style-guide.mdwn
===================================================================
--- trunk/sviki/fsf/bash-style-guide.mdwn 2026-03-25 05:17:35 UTC (rev
865)
+++ trunk/sviki/fsf/bash-style-guide.mdwn 2026-04-14 11:42:03 UTC (rev
866)
@@ -228,8 +228,27 @@
# Gotchas
+## Replacing a script file can screw up running instances
+
+Solution: For any script file that might get replaced with a new version, eg: a
+long running script or a cronjob, make a `main` function which
+contains all important logic & commands and make it be the last command
+in the file.
+
+Background: Bash doesn't read further in the script than it needs to and
+when you replace the script, bash will try to read the next line from
+the new file from the offset it was at in the original file. This
+usually means it reads from somewhere in the middle of a line. Usually,
+running part of a line just fails, but you could get very unlucky. With
+a main function doing everything, bash has to parse the whole file
+before running main and so there is no opportunity for a replaced file
+to cause problems.
+
+## unusual behavior of || + &&
+
Don't mistake command conditionals for a boolean expression, they have
-different rules. Command conditionals pair together 2 commands. For example:
+different rules, aka operator precedence. Command conditionals pair
+together 2 commands. For example:
```
if echo 1 || echo 2 && echo 3; then