Skip to content

Quoting of associative array subscripts in assignments (ble.sh) #646

Description

@akinomyoga

Oil requires the quoting of the associative array subscripts in left hand side of assignments but doesn't require it in the keys of the designated initializer. Is there rationale on this behavior? I feel it is natural not to require quoting also in assignments.

$ bin/osh -c 'declare -A d; d[a]=123'
  declare -A d; d[a]=123
                ^~
[ -c flag ]:1: fatal: Associative array keys must be strings: $x 'x' "$x" etc.
$ bin/osh -c 'declare -A d=([a]=123)'
$

Note that Zsh also behaves differently from Bash here. Zsh accepts quoteless subscripts in assignments like Bash, but it doesn't remove "" in the subscripts in assignments.

$ zsh -c 'declare -A d; d[a]=1; declare -p d'
typeset -A d=( [a]=1 )
$ zsh -c 'declare -A d=([a]=1); declare -p d'
typeset -A d=( [a]=1 )
$ zsh -c 'declare -A d; d["a"]=1; declare -p d'
typeset -A d=( ['"a"']=1 )
$ zsh -c 'declare -A d=(["a"]=1); declare -p d'
typeset -A d=( [a]=1 )

No activity

Activity on this issue will appear here.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions