summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-11-22 03:08:59 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-11-22 03:08:59 +0300
commit98d438b497e1f2da1776367825552910b1a52bcc (patch)
tree7de0c2bf81692a66b9f707de5e9692ca766e9a73
parentcygwin.md: update (diff)
downloadnotes-98d438b497e1f2da1776367825552910b1a52bcc.tar.gz
notes-98d438b497e1f2da1776367825552910b1a52bcc.zip
bash.md: how to declare arrays
-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