diff options
-rw-r--r-- | bash.md | 24 |
1 files changed, 13 insertions, 11 deletions
@@ -6,25 +6,27 @@ GNU `bash` ### Expansion -Yes: +#### Do func ${arr[@]+"${arr[@]}"} -No: +#### Don't - func "${arr[@]}" # doesn't work with `nounset` - func "${arr[@]+"${arr[@]}"}" # doesn't work with ('') + func "${arr[@]}" # Doesn't work with `nounset`. + func "${arr[@]+"${arr[@]}"}" # Doesn't work properly with `declare -a arr=('')`. ### `unset` -Yes: +#### Do unset -v 'arr[$i]' -No: +#### Don't - 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 + unset -v arr[x] # May break due to globbing. + unset -v arr[$i] # The same as above + possibly a pair of quotes is + # missing. + unset -v 'arr["x"]' # Doesn't work for some reason. + unset -v 'arr["]"]' # The same as above; just highlighting the problem + # with funny characters in array indices. + # An insightful discussion: https://lists.gnu.org/archive/html/help-bash/2016-09/msg00020.html. |