summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorEgor Tensin <Egor.Tensin@gmail.com>2016-10-10 20:06:51 +0300
committerEgor Tensin <Egor.Tensin@gmail.com>2016-10-10 20:06:51 +0300
commita7b8cb5bd8c17b174316e8bc8dc649612c478da7 (patch)
tree933c1be2ad0c15a9cc3c63aa25a5ecf6361ce00d
parentbash.md: code style (diff)
downloadnotes-a7b8cb5bd8c17b174316e8bc8dc649612c478da7.tar.gz
notes-a7b8cb5bd8c17b174316e8bc8dc649612c478da7.zip
bash.md: arrays & `unset`
-rw-r--r--bash.md30
1 files changed, 24 insertions, 6 deletions
diff --git a/bash.md b/bash.md
index aba50d5..ca3c722 100644
--- a/bash.md
+++ b/bash.md
@@ -1,12 +1,30 @@
GNU `bash`
==========
-1. (Associative) arrays
- * Yes:
+(Associative) arrays
+--------------------
- func ${arr[@]+"${arr[@]}"}
+### Expansion
- * No:
+Yes:
- func "${arr[@]}" # doesn't work with `nounset`
- func "${arr[@]+"${arr[@]}"}" # doesn't work with ('')
+ func ${arr[@]+"${arr[@]}"}
+
+No:
+
+ func "${arr[@]}" # doesn't work with `nounset`
+ func "${arr[@]+"${arr[@]}"}" # doesn't work with ('')
+
+### `unset`
+
+Yes:
+
+ unset -v 'arr[$i]'
+
+No:
+
+ unset -v arr[x] # globbing
+ unset -v arr[$i] # the same problem + quoting
+ unset -v 'arr["x"]' # doesn't work for some reason
+ unset -v 'arr["]"]' # the same as above; just to highlight the problem with funny characters in array indices
+ # insightful discussion: https://lists.gnu.org/archive/html/help-bash/2016-09/msg00020.html