zsh-users
 help / color / mirror / code / Atom feed
* syntax question
@ 2018-03-21 23:15 Ray Andrews
  2018-03-22  1:30 ` Bart Schaefer
  0 siblings, 1 reply; 4+ messages in thread
From: Ray Andrews @ 2018-03-21 23:15 UTC (permalink / raw)
  To: zsh Users

${${(z)string}[1]}

... that does what I expect, and it's readable, however I'm curious why 
this does not say the same thing:

${(z)string[1]}

... How can that mean anything different?  It seems to just sorta get to 
the point more quickly and given the " (z) " it seem unintuitive that it 
would only print the first character just as:

${string[1]}

... does.  So in the second line the " (z) " seems to do nothing.  I'd 
expect the first two lines to be semantically the same and the third 
line to be a single character.  Is this explainable?  I know it's a 
nit-pick but I'd like to understand it.



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

* Re: syntax question
  2018-03-21 23:15 syntax question Ray Andrews
@ 2018-03-22  1:30 ` Bart Schaefer
  2018-03-23 16:44   ` Sebastian Gniazdowski
  0 siblings, 1 reply; 4+ messages in thread
From: Bart Schaefer @ 2018-03-22  1:30 UTC (permalink / raw)
  To: Ray Andrews; +Cc: zsh Users

On Wed, Mar 21, 2018 at 4:15 PM, Ray Andrews <rayandrews@eastlink.ca> wrote:
> ${${(z)string}[1]}
>
> ${(z)string[1]}
>
> ... How can that mean anything different?

Operator precedence.  The second one is equivalent to
${(z)${string[1]}}, as you observed.


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

* Re: syntax question
  2018-03-22  1:30 ` Bart Schaefer
@ 2018-03-23 16:44   ` Sebastian Gniazdowski
  0 siblings, 0 replies; 4+ messages in thread
From: Sebastian Gniazdowski @ 2018-03-23 16:44 UTC (permalink / raw)
  To: Bart Schaefer, Ray Andrews; +Cc: zsh Users

On 22 marca 2018 at 02:30:52, Bart Schaefer (schaefer@brasslantern.com) wrote:
> On Wed, Mar 21, 2018 at 4:15 PM, Ray Andrews wrote:
> > ${${(z)string}[1]}
> >
> > ${(z)string[1]}
> >
> > ... How can that mean anything different?
> 
> Operator precedence. The second one is equivalent to
> ${(z)${string[1]}}, as you observed.

Also, better to use (Az), utilizing your underrated patch, because:

% a='abcd'
% echo ${${(z)a}[1]}
a

-- 
Sebastian Gniazdowski
psprint /at/ zdharma.org


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

* syntax question
  2015-08-30 19:13 zsh 5.1 released [user] Peter Stephenson
@ 2015-09-06 16:50 ` Ray Andrews
  0 siblings, 0 replies; 4+ messages in thread
From: Ray Andrews @ 2015-09-06 16:50 UTC (permalink / raw)
  To: zsh-users

If I have a variable who's name is partially constructed from the 
contents of another variable:

        eval "t$bb="
        eval "echo \$t$bb"

... the above handles it all fine, but is there a simpler syntax?  I 
understand that most/much of what 'eval' does can be written more elegantly.


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

end of thread, other threads:[~2018-03-23 16:52 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-03-21 23:15 syntax question Ray Andrews
2018-03-22  1:30 ` Bart Schaefer
2018-03-23 16:44   ` Sebastian Gniazdowski
  -- strict thread matches above, loose matches on Subject: below --
2015-08-30 19:13 zsh 5.1 released [user] Peter Stephenson
2015-09-06 16:50 ` syntax question Ray Andrews

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).