[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Savannah-cvs] [814] bash style guide improvements
From: |
iank |
Subject: |
[Savannah-cvs] [814] bash style guide improvements |
Date: |
Fri, 31 Jan 2025 22:29:06 -0500 (EST) |
Revision: 814
http://svn.savannah.gnu.org/viewvc/?view=rev&root=administration&revision=814
Author: iank
Date: 2025-01-31 22:29:05 -0500 (Fri, 31 Jan 2025)
Log Message:
-----------
bash 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 2024-10-16 17:09:57 UTC (rev
813)
+++ trunk/sviki/fsf/bash-style-guide.mdwn 2025-02-01 03:29:05 UTC (rev
814)
@@ -72,7 +72,7 @@
Before using any script, it should have no output from:
```
-shellcheck -x -e 2046,2068,2086,2206,2029,2033,2054,2164,2254,2317 SCRIPT_FILE
+shellcheck -x -e 2046,2068,2086,2206,2029,2033,2054,2164,2254,2231,2317
SCRIPT_FILE
```
### Reasons for the exceptions
@@ -96,6 +96,7 @@
# 2086 = unquoted $var
# 2206 = unquoted $var in array=($var)
# 2254 = unquoted $var in case x in $var)
+# 2231 = unquoted $var in $var/*
```
Miscellaneous exceptions:
@@ -115,6 +116,9 @@
mistake based on how other languages work; but commas are not special
in BASH, and even unquoted, they are legitimate array elements.
+# 2119 = Suggestion to pass "$@" to a function that uses arguments. This
+ is mostly a false positive and would almost always be very obvious if not.
+
# 2164 = `cd` without condition for failure. Reason: We use automatic error
handling.
@@ -454,13 +458,13 @@
Check for empty & unset variables with `\[[ $var ]]`.
-Optionally use `set -u` when using automatic error handling. It can
-prevent errors in somewhat complicated scripts where you set variables
-within conditionals. It also makes code verbose because unset/empty
-variables are often useful and so then you need to set variables to
-empty, eg `x=`, complicating your code and potentially also leading to
-bugs. Avoid relying on set -u. If you see a situation where you think
-set -u might catch an error, add an explicit test for an empty variable.
+Avoid use of `set -u`, except for writing a library you want to be
+compatible with it. It can add bugs as much as preventing them because
+empty variables are useful and it adds complexity. Additionally, it has
+very scary undocumented behavior: under set -u, the command
+"${#unbound_var[@]}" will cause a function return that is not an error,
+but $? is set to 1. I don't know what other kind of screwy things might
+happen under set -u.
Prefer `$var` except when `${var}` is necessary or adds clarity, like
`"comb${x}ining strings"`.
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [Savannah-cvs] [814] bash style guide improvements,
iank <=