From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 17602 invoked by alias); 29 Dec 2017 18:43:37 -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: List-Unsubscribe: X-Seq: 23022 Received: (qmail 28629 invoked by uid 1010); 29 Dec 2017 18:43:36 -0000 X-Qmail-Scanner-Diagnostics: from mail-qt0-f178.google.com by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.99.2/21882. spamassassin: 3.4.1. Clear:RC:0(209.85.216.178):SA:0(-2.6/5.0):. Processed in 2.295385 secs); 29 Dec 2017 18:43:36 -0000 X-Spam-Checker-Version: SpamAssassin 3.4.1 (2015-04-28) 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, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_PASS,T_DKIM_INVALID autolearn=ham autolearn_force=no version=3.4.1 X-Envelope-From: schaefer@brasslantern.com X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=LitufS1y8jF/C38Krk8Fsc8maMHjTED+7Hoj4NtkClQ=; b=kgv6DfUhse7KcvXmcEYgW7Hw0Ed67F2h9D1By5JZ2CJAn/JloADc0+y7bMwvqShLUL spSIle1nxz3HoQwnQJKEYq3geuvCeBLHmdKqJfvlx0oJ8+I7RyOo7GO10wfxWzL9jAGl KX8eye7aWrlqvwUwoX7q85aPCQXhwLTbCu+QlXsVNbJcgGeBf3hZzvNxZWvv3IqcZi4u drjrpr/RppwlRrzWsxLgC5l/XdClKrrJkaCzzrGrjpvVvGgqtqRVtq3VH0EV0LJcvvU3 aEnAIZNLfidc7HzKxQ0e03VCVPgRcPgCqonN5RSVCRCXKb0aHk2wKxd5TWCofA0imiVl AIwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=LitufS1y8jF/C38Krk8Fsc8maMHjTED+7Hoj4NtkClQ=; b=GQjKe5Q+W2hgCZ6QL/RriLJ+ONXVCCQTl4yCUBuHMLVDv5DstevPEii1vXPAcZB8Wu brLofPS3Ct+1mBbweh7AjUD6Yx2qOCAu1l9kVpK+Z7WaP1LV282IQAfI/JWk+zYwuTIy dnfHSxnyvtUvKIBWQ/ZE1QAEBzj7/JrxJap8+JvZsaZ1N7xsOKutk/hP/CE8ICQubiv9 pl0R3hadyMraVDRXgPU5TWpGyVlCveeNcY8A7GQp68gP5E/NsFioe6xY3R0pnTSYcLp+ O4rPsNKivVjAgVN3yjZ5HFA+ZGA84AnI92rWsWOek4u8bzfc6B7imDIKok1NafZaYOcA JUMg== X-Gm-Message-State: AKGB3mK8Fo4mMzTg59BVL9XuXEHDbOcnl6ocECNk4isj96LkCFD/njSS ixsY+Hx+GRfARMJH/y3GO5qqy+nbsraSDHn2VsvYwIbM X-Google-Smtp-Source: ACJfBou3gxFTMEVedMvHkpFnmmixxlk5ZxwYeaq4ZXxvefyuPlTF/Bu/2mZ/T7LuA5Wr8IzS/koGvGBrX87FzaQ75hw= X-Received: by 10.200.53.238 with SMTP id l43mr47965483qtb.269.1514573011096; Fri, 29 Dec 2017 10:43:31 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: From: Bart Schaefer Date: Fri, 29 Dec 2017 10:43:30 -0800 Message-ID: Subject: Re: Mix and match parameter expansion flags and sub-scripting flags + quoting To: zsh Content-Type: text/plain; charset="UTF-8" On Fri, Dec 29, 2017 at 7:29 AM, Jim wrote: > Hello, > > The intent is, using only "native zsh" tools, return the 'shell' > as set in /etc/passwd for my own $USER without using any external > utilities, gnu or otherwise. As in UNIX/Linux, zsh also has more then > one way of doing the same thing. So as a training exercise I decided > to use as many variants as I could to do the same thing. In the process > I found that what I though would work, did not return the intended > result. I haven't gone through your cases in any detail, but there are almost certainly three things causing your problems: (1) Nested expansions plus quoting cause an array in the inner expansion to be joined into a string in most cases, unless you use special syntax to preserve the array (2) Single-element arrays behave like scalars (strings) in several cases (3) Subscript syntax applies to scalars, to extract substrings Those last two put together can cause a lot of head-scratching. Recent zsh extended ${(A)array} to mean "assure $array continues to be treated as an array, even when it would otherwise become a string" specifically to avoid this issue. Some of your examples work around it by using the (w) subscript flag, but that isn't quite the same, because it still starts from a string and re-splits the string before indexing. In older zsh for most cases you can preserve array-ness by using the (@) flag, there are just a few [item (2) above] where that didn't work which caused us to provide (A). Compare: % x=("abc def") % print ${x[1]} abc def % print ${${x}[1]} abc def % print "${${x}[1]}" a % print ${"${x}"[1]} a % print ${"${x}"[(w)1]} abc % print ${"${(A)x}"[1]} abc def % print "${${(@)x}[1]}" abc def Figuring out at what level of a nested expansion you need to add (A) or (@) is the other part of the equation. Sometimes you need to add an extra level of nesting just to force (A) to be applied to the correct value. > My distributions currently distributes ZSH_VERSION 5.3.1. That should be new enough for (A) to work.