diff options
author | Egor Tensin <Egor.Tensin@gmail.com> | 2016-11-22 03:08:59 +0300 |
---|---|---|
committer | Egor Tensin <Egor.Tensin@gmail.com> | 2016-11-22 03:08:59 +0300 |
commit | 98d438b497e1f2da1776367825552910b1a52bcc (patch) | |
tree | 7de0c2bf81692a66b9f707de5e9692ca766e9a73 | |
parent | cygwin.md: update (diff) | |
download | notes-98d438b497e1f2da1776367825552910b1a52bcc.tar.gz notes-98d438b497e1f2da1776367825552910b1a52bcc.zip |
bash.md: how to declare arrays
-rw-r--r-- | bash.md | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -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 |