zsh-users
 help / color / mirror / code / Atom feed
* Associative array, brace-free subscripting: key with spaces
@ 2015-10-29 17:17 Clint Hepner
  2015-10-29 17:28 ` Peter Stephenson
  0 siblings, 1 reply; 2+ messages in thread
From: Clint Hepner @ 2015-10-29 17:17 UTC (permalink / raw)
  To: <zsh-users@zsh.org>

[-- Attachment #1: Type: text/plain, Size: 428 bytes --]

Consider the array

    typeset -A b
    b=("a b c" d)

The following correctly expands to "d"

    ${b[a b c]}

but this results in a "bad subscript" error:

    $b[a b c]

I can't seem to find anything in the man page about why this would
be the case. It seems to be a parsing error, since using a separate
parameter to store the key works fine as well:

    z="a b c"
    print $b[$z]

--
Clint Hepner
clint.hepner@gmail.com

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Associative array, brace-free subscripting: key with spaces
  2015-10-29 17:17 Associative array, brace-free subscripting: key with spaces Clint Hepner
@ 2015-10-29 17:28 ` Peter Stephenson
  0 siblings, 0 replies; 2+ messages in thread
From: Peter Stephenson @ 2015-10-29 17:28 UTC (permalink / raw)
  To: <zsh-users@zsh.org>

On Thu, 29 Oct 2015 13:17:17 -0400
Clint Hepner <clint.hepner@gmail.com> wrote:
> Consider the array
> 
>     typeset -A b
>     b=("a b c" d)
> 
> The following correctly expands to "d"
> 
>     ${b[a b c]}
> 
> but this results in a "bad subscript" error:
> 
>     $b[a b c]

Without the surrounding brace, the spaces separate words, so it looks at
"$b[a" and doesn't like it.

pws


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2015-10-29 17:28 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-10-29 17:17 Associative array, brace-free subscripting: key with spaces Clint Hepner
2015-10-29 17:28 ` Peter Stephenson

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).