summaryrefslogtreecommitdiffstatshomepage
path: root/bash.md
blob: 1ca3d13d6398f6a973ad4f695f42279a671c5e42 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
GNU `bash`
==========

(Associative) arrays
--------------------

### Expansion

#### Do

    func ${arr[@]+"${arr[@]}"}

#### Don't

    func "${arr[@]}"                # Doesn't work with `nounset`.
    func "${arr[@]+"${arr[@]}"}"    # Doesn't work properly with `declare -a arr=('')`.

### `unset`

#### Do

    unset -v 'arr[$i]'

#### Don't

    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.