summaryrefslogtreecommitdiffstatshomepage
path: root/bash.md
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--bash.md20
1 files changed, 20 insertions, 0 deletions
diff --git a/bash.md b/bash.md
index 628bfa8..6f729a0 100644
--- a/bash.md
+++ b/bash.md
@@ -4,6 +4,26 @@ GNU `bash`
(Associative) arrays
--------------------
+### Declaration
+
+`"${#xs[@]}"` doesn't work with `nounset` if `xs` wasn't defined, i.e. was
+declared with either of
+
+ local -a xs
+ declare -a xs
+ local -A xs
+ declare -A xs
+
+Therefore, if you want to extract the length of an array, append `=()` to the
+statements above.
+
+ local -a xs=()
+ declare -a xs=()
+ ...
+
+And now `"${#xs[@]}"` works with `nounset`.
+It doesn't affect expansion (see below) though.
+
### Expansion
#### Do