zsh-users
 help / color / mirror / code / Atom feed
From: Ray Andrews <rayandrews@eastlink.ca>
To: zsh-users@zsh.org
Subject: Re: ${var: -1:1} vs. ${var:-1:1}
Date: Sat, 17 Nov 2012 18:25:20 -0800	[thread overview]
Message-ID: <50A84710.5050502@eastlink.ca> (raw)
In-Reply-To: <121117173135.ZM9888@torch.brasslantern.com>

On 17/11/12 05:31 PM, Bart Schaefer wrote:
> On Nov 17,  2:56pm, Ray Andrews wrote:
> } Subject: Re: ${var: -1:1} vs. ${var:-1:1}
> }
> } > if you don't put a space there then the parser thinks that this the
> } > "${variable:-default} syntax which means "expands to the variable's
> } > content if the variable is set and to 'default' if it is unset".
> } >
> } > So the '1:1' is interpreted as the 'default'. You probably never saw
> } > that result because you were trying to extract the last character from
> } > a string, meaning you always used a variable that was set.
> } >
> } I see.  But it's still lousy syntax IMHO.
>
> Well, the var:-word syntax long predates :N:M for string slicing.  Zsh
> actually can (and always has) used just ${var[-1]} for the last character
> of a string, the :N:M syntax was invented by bash and merely adopted by
> zsh for compatibility.
>
Yeah, I guess it's one of those things where it would be different if 
the whole thing could be rethought, but traditions must be 
accommodated.  I guess if you want a blank sheet of paper, that's when 
you start again with a new shell. But thanks for '${var[-1]}' that's a 
better syntax all around.


      reply	other threads:[~2012-11-18  2:25 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-11-17 21:10 Ray Andrews
2012-11-17 21:48 ` Moritz Bunkus
2012-11-17 22:56   ` Ray Andrews
2012-11-18  1:31     ` Bart Schaefer
2012-11-18  2:25       ` Ray Andrews [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=50A84710.5050502@eastlink.ca \
    --to=rayandrews@eastlink.ca \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).