zsh-users
 help / color / mirror / code / Atom feed
From: Moritz Bunkus <moritz@bunkus.org>
To: Ray Andrews <rayandrews@eastlink.ca>
Cc: zsh-users@zsh.org
Subject: Re: ${var: -1:1} vs. ${var:-1:1}
Date: Sat, 17 Nov 2012 22:48:56 +0100	[thread overview]
Message-ID: <CANPayMQK+nYt2aUCrYF1ePUq0HDmByT3kAS7UXtE-ZutxyLJnw@mail.gmail.com> (raw)
In-Reply-To: <50A7FD3C.9070306@eastlink.ca>

Hey,

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". Can
be seen easily with:

[0 mosu@sweet-chili ~] echo ${thisvarisnotset:-1:1}
1:1

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.

Kind regards,
mosu


  reply	other threads:[~2012-11-17 21:57 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 [this message]
2012-11-17 22:56   ` Ray Andrews
2012-11-18  1:31     ` Bart Schaefer
2012-11-18  2:25       ` Ray Andrews

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=CANPayMQK+nYt2aUCrYF1ePUq0HDmByT3kAS7UXtE-ZutxyLJnw@mail.gmail.com \
    --to=moritz@bunkus.org \
    --cc=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).