From a7b8cb5bd8c17b174316e8bc8dc649612c478da7 Mon Sep 17 00:00:00 2001 From: Egor Tensin Date: Mon, 10 Oct 2016 20:06:51 +0300 Subject: bash.md: arrays & `unset` --- bash.md | 30 ++++++++++++++++++++++++------ 1 file 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 -- cgit v1.2.3