summaryrefslogtreecommitdiff
path: root/HACKING/code-quality.md
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-04-15 17:37:46 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-04-15 17:37:46 -0400
commitbb819d5ef6c6dc68da524de07991eae2a2c3a3af (patch)
treefb5349192696db11086dc85820b0bf4b4e5d6c95 /HACKING/code-quality.md
parent7bd29f4570869e1db2992e337f86e93f1cfa43e7 (diff)
Use a better technique for dealing with empty arrays when `set -u`.
https://news.ycombinator.com/item?id=11497636
Diffstat (limited to 'HACKING/code-quality.md')
-rw-r--r--HACKING/code-quality.md3
1 files changed, 2 insertions, 1 deletions
diff --git a/HACKING/code-quality.md b/HACKING/code-quality.md
index a520ce5..8efd561 100644
--- a/HACKING/code-quality.md
+++ b/HACKING/code-quality.md
@@ -49,7 +49,8 @@ Use `set -u` if you can; it makes using an unset variable an error.
- If a variable not being set is valid (perhaps a configuration
option), use `${var:-}` when accessing it to suppress the error.
- An empty array counts as unset, so if you have an array that may be
- empty, use `set +u` before accessing it.
+ empty, use `${var+"${var[@]}"}` (don't put quotes around the outer
+ pair of braces) to only access it if it's non-empty.
- The reason for this is that a normal string variable is basically
an array with length=1; an unset variable looks like an array
with length=0. Weird stuff.