From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: ${var: -1:1} vs. ${var:-1:1}
Date: Sat, 17 Nov 2012 17:31:35 -0800 [thread overview]
Message-ID: <121117173135.ZM9888@torch.brasslantern.com> (raw)
In-Reply-To: <50A8161D.1030302@eastlink.ca>
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.
next prev parent reply other threads:[~2012-11-18 1:31 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 [this message]
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=121117173135.ZM9888@torch.brasslantern.com \
--to=schaefer@brasslantern.com \
--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).