Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: A bug or improperly formatted script
- X-seq: zsh-users 22499
- From: Jim <linux.tech.guy@xxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: Re: A bug or improperly formatted script
- Date: Sat, 25 Feb 2017 16:53:06 -0600
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:reply-to:in-reply-to:references:from:date:message-id :subject:to; bh=ywzEpSWW4Pppd6fmx+rMZE6dHjpTGl6UT2huQ3yhUOc=; b=uSW6dKXrkrTye92nJmTyFnxpcSBI/eqvnlxwWxHZqALnetG8j34Nvo7tiXvbrYtaxk QZEtd5w6j/QSLk0XhdZrq09MEEEYMtNn9zaqAfr8cA3ilW2yxfwZqUZm19j7MbfFpofc mX2ER8kYV/TKquD6tGCoStiY3sB/S0+DnsKIFvy6bs9GWGFjM2yTDi4ICeeKneQk4LIw fp9XZp6gd9Cwddv/IBVm4qiefNjI6XlHaYSiQ75bdwGi6hrjmRfg736tWxr+FxxLTFyL 7ZJ7ZwKz5Fb98lIKi6zDi/tk3HIhAcGv+kwnZej9hlWzFF8XvVDRHIK0K1m2gSiRJtpb 5IwQ==
- In-reply-to: <170225141211.ZM20788@torch.brasslantern.com>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <CA+rB6GJoCDbdEVYR-zYEh6P0Oau7VAxQeW6UcnksdeB3hvL=HQ@mail.gmail.com> <170225141211.ZM20788@torch.brasslantern.com>
- Reply-to: linuxtechguy@xxxxxxxxx
On Sat, Feb 25, 2017 at 4:12 PM, Bart Schaefer <schaefer@xxxxxxxxxxxxxxxx>
wrote:
> Yes, this is a known / traditional behavior, and it somewhat regularly
> comes up in examples where a program has been tested only in the "more
> than one element" cases.
>
> The problem is that nesting ${${...}} "wants" to treat the inner ${...}
> as a scalar, and will do so unless something else forces it to be an
> array. (f) doesn't accomplish that because $(dirs -v) produces only
> one line of output with the final newline stripped, so there is nothing
> for (f) to split on. (@) won't accomplish it because it only means
> that things that are already arrays should remain so.
>
> So what can be done to force interpretation as an array here? Unless
> someone else has a better solution, the answer is to forcibly assign
> the result to an array variable:
>
> print $((${${(z)${(Af)reply::="$(dirs -v)"}[-1]}[1]} + 1))
>
Good to know. So in my original email the alternate example
print $((${(z)${(fO)"$(dirs -v)"}[1][1]} + 1))
was this forcing it to an array or was it a fluke? I assumed(bad
thing to do) that it had and "[1][1]" would then work properly. It does
return the desired results for a single or multiple line output from
"dirs -v".
> Once we are expanding ${reply} rather than ${"$(dirs -v")} the array
> property is preserved and [-1] remains an array subscript instead of
> becoming a scalar string slice.
>
> A follow-up to this is going to zsh-workers.
>
I will forward this on to zsh-lovers.
Thanks for your help.
Jim
Messages sorted by:
Reverse Date,
Date,
Thread,
Author