[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Help-bash] Expansions in associative array subscripts
From: |
Jesse Hathaway |
Subject: |
Re: [Help-bash] Expansions in associative array subscripts |
Date: |
Wed, 7 Aug 2019 09:19:17 -0500 |
On Wed, Aug 7, 2019 at 7:49 AM Greg Wooledge <address@hidden> wrote:
> The warning is about cases like this:
>
> $ touch a1
> $ a=(zero one two)
> $ unset a[1]
> $ declare -p a
> declare -a a=([0]="zero" [1]="one" [2]="two")
>
> In that example, a[1] is globbed to a1 because of the file named a1 in
> the current working directory. So the resulting command is unset a1,
> which is very different from unset 'a[1]'.
>
> $ unset 'a[1]'
> $ declare -p a
> declare -a a=([0]="zero" [2]="two")
That is nasty, thanks for detailed explanation, shellcheck provides a
good warning message as well:
unset a[1]
^--^ SC2184: Quote arguments to unset so they're not glob expanded.
For more information:
https://www.shellcheck.net/wiki/SC2184 -- Quote arguments to unset
so they'...