From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 9583 invoked by alias); 18 Nov 2012 02:25:28 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 17408 Received: (qmail 15212 invoked from network); 18 Nov 2012 02:25:25 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 Received-SPF: pass (ns1.primenet.com.au: SPF record at _spf.eastlink.ca designates 24.224.136.30 as permitted sender) X-Authority-Analysis: v=2.0 cv=FqZdZBXq c=1 sm=1 a=bWgGDZnfoeonEsxmbE2SBg==:17 a=-1ZKr4ocusoA:10 a=UjUtIS2Rs34A:10 a=8nJEP1OIZ-IA:10 a=kourTHHxn5YA:10 a=hR4dtswtJ8lwQ_XWragA:9 a=wPNLvfGTeEIA:10 a=bWgGDZnfoeonEsxmbE2SBg==:117 Message-id: <50A84710.5050502@eastlink.ca> Date: Sat, 17 Nov 2012 18:25:20 -0800 From: Ray Andrews User-Agent: Mozilla/5.0 (X11; Linux i686; rv:16.0) Gecko/20121026 Thunderbird/16.0.2 MIME-version: 1.0 To: zsh-users@zsh.org Subject: Re: ${var: -1:1} vs. ${var:-1:1} References: <50A7FD3C.9070306@eastlink.ca> <50A8161D.1030302@eastlink.ca> <121117173135.ZM9888@torch.brasslantern.com> In-reply-to: <121117173135.ZM9888@torch.brasslantern.com> Content-type: text/plain; charset=ISO-8859-1; format=flowed Content-transfer-encoding: 7bit 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.