Revision: 820
http://svn.savannah.gnu.org/viewvc/?view=rev&root=administration&revision=820
Author: iank
Date: 2025-03-11 23:53:09 -0400 (Tue, 11 Mar 2025)
Log Message:
-----------
general style guide improvements
Modified Paths:
--------------
trunk/sviki/fsf/bash-style-guide.mdwn
Modified: trunk/sviki/fsf/bash-style-guide.mdwn
===================================================================
--- trunk/sviki/fsf/bash-style-guide.mdwn 2025-03-12 03:53:05 UTC (rev
819)
+++ trunk/sviki/fsf/bash-style-guide.mdwn 2025-03-12 03:53:09 UTC (rev
820)
@@ -72,7 +72,8 @@
Before using any script, it should have no output from:
```
-shellcheck -x -e 2046,2068,2086,2206,2029,2033,2054,2164,2254,2231,2317
SCRIPT_FILE
+# -ax : check sourced files
+shellcheck -ax -e 2046,2068,2086,2206,2029,2033,2054,2164,2254,2231,2317
SCRIPT_FILE
```
### Reasons for the exceptions
@@ -225,7 +226,37 @@
Put all functions together near the top of the file after includes,
constants, and `set` statements.
+# Gotchas
+Don't mistake command conditionals for a boolean expression, they have
+different rules. Command conditionals pair together 2 commands. For example:
+
+```
+if echo 1 || echo 2 && echo 3; then
+ echo 4
+fi
+output:
+1
+3
+4
+
+cd $(mktemp -d)
+if [[ $(echo t|tee 1) || $(echo t|tee 2) && $(echo t|tee 3) ]]; then
+ ls -1; echo 4
+fi
+# output:
+1
+4
+
+# To make the 1st example be like the 2nd:
+if echo 1 || { echo 2 && echo 3; }; then
+ echo 4
+fi
+# output
+1
+4
+```
+
# Error handling
There are 2 options: automatic and manual. Pick one and use it consistently
throughout your script.