From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 25727 invoked from network); 16 Nov 2022 01:50:50 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 16 Nov 2022 01:50:50 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1668563450; b=F3l/xs1mWeVy1hO5iQkfrp2VhcKuO+bSSud299EBxA7idAT7jr5u7rECfqY+pv/Y6Sy9he9sYm CxbbCJfI3k15+nLHYXdI++jbNdiHr4ezzGMMdorPE6q3Jvq2EAASydrqBpmCnPQhNpof61fqBm L/ilngbD2y0hAwiZlMA90ltIWsDJUGSTXAQgiwr/4KYaH6vWxQshypvMjRnX9AhFtBqrYbbnJm +KjN9ttI20xBOnzQdJEnh7t1Z4g0CMBHUbzaL6UvpwpzMc1w+Llg/cSQilGdDb+PE3IlERuZ9j ICN9m3dNZ0s2taU5vltnKbLhODqzhZOLuSm2Rxqr/QY74A==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ej1-f44.google.com) smtp.remote-ip=209.85.218.44; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1668563450; bh=I9F+sk916eicmdiSPQxwUT0mVdZG8AegF1f+hDhmk6Y=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=AXNO5wOlP1s01WdOmL+1EdO7VYpNCx9XnbI2X6CbtSj8NakFtwFh2Bup2IV4txCccHg78T5uXT 1XOTEoNpixPw4YCoRV37DNGx7pls3cud5h/wpqRkCrWDm+fMB+cpRwoS0LFPZDtCR1A0nbM26n 18iFMU6fkzqep18oYfihhxjpqCQ7ARhPXDTWXVasRtyZwHtr1ZQHq4upHu7YesvVl0wQ7gJBKV LGGyDlcZB2fTaoeQWawYI13j37bjme5v4qFx3Elc2AAt5xDDvN8o6FcDayQc7H08Lz/tfI5hI1 +m9N2JX91UK9xRBLxfJpTFZYpFL7ukIEYJDYSMgHYR0j/Q==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20210803; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=lf8hUQ29PbKZJ5RIowUf9ZroaFJveyVCaAzyOasGnPs=; b=L08EnzyfMkvicL03Mbd+IEi1Kp EzjJatWr1A9c9t1o20RUi3xzYo/XT7UdkKljw3KxzP0yJ0u6+wx5nClHF0ZVS0a+9Pw/fFDPQe/GU 8nzSrWrxMyiFneSAD7maPKrpJnyCh3meWF1JvU0NpFqjB40wNanDZWvRS093089wlp1zS6XmVp3vL EWHTV6JdTX+9atljfDlsdSQup5enYwqZdTcVl1eEJM2QUlFjKAI4ELUQa2Yo0POUETCeCeNm/6YKa hGPcJCSEU968oh9NTQJXVcpfZU8je9+tFYHRao944qCVvnVDVbghOm70YD3xEhv4cPWafWpKeZCxq +QV+o1tA==; Received: by zero.zsh.org with local id 1ov7Zh-000BKg-4D; Wed, 16 Nov 2022 01:50:49 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ej1-f44.google.com) smtp.remote-ip=209.85.218.44; dkim=pass header.d=brasslantern-com.20210112.gappssmtp.com header.s=20210112 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ej1-f44.google.com ([209.85.218.44]:40565) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1ov7Yw-000Ad9-N5; Wed, 16 Nov 2022 01:50:03 +0000 Received: by mail-ej1-f44.google.com with SMTP id kt23so40672393ejc.7 for ; Tue, 15 Nov 2022 17:50:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20210112.gappssmtp.com; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:from:to:cc:subject:date:message-id:reply-to; bh=lf8hUQ29PbKZJ5RIowUf9ZroaFJveyVCaAzyOasGnPs=; b=BVcImHaJGuNLvhE+O0Shp1hCAf7pIhhUuX7fXYUsEIyoQBpx/ZnCpGxU5zaYUS6qtx 5rZpYFB7qhiCj3kpsD8KbQdX5B+y7yAT89rAtWp4TaCKOW8rPgaZjQn74zZcceUJxIl8 D75AaHeqVSjeh6U/caNudrCbv4/jmXrgDO0DA+G+5Z+7i+b1c0E+UwqP6BVkY+3OlXuf 7fimEmMIwkWcrf95mU8t98bdpmqFNUsVnzkR4gKb7LYWj0aFI/AwrUEzhyPfldv7ytKp TtBhNMWMeb2Ho2y5ODfish30VrGJ7/fVvYbcn3b+Q9eaZJun9E/DSTZSBxlm7nx8nvYi R85w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:subject:message-id:date:from:in-reply-to:references :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=lf8hUQ29PbKZJ5RIowUf9ZroaFJveyVCaAzyOasGnPs=; b=45Jaa6zpOVCVstdUzG7t3q9tYRorfggbHF7GUvPt1+tGG1CmuRBRVOoJbkKqJ+xe+j hSRTPNqKnzASAaPWmTKcwI77+XEewJqqv4y/7W+k/zS3Cr+9THdYr7hpZ/0bDoMzJG0x 3yM1CQ7SuyxWSFf9C6I+5ooRb8POUkakUd3DK3Xwj5pGq5goWWLeLmYpz5QGV7aqm2cG pU8Ir8U9EEK/tgo/R4ZfUA845NNloyK0U53YEhpI7Qh/WAJNnH5BGdk+q9byqBVO19KU EWvkn50o2zF0DkhyFuUX5iXmRZ2vfJciCBD5z3lrJCWR2Aa7dFrhrOFmIMjmgQR1WW+O IxBQ== X-Gm-Message-State: ANoB5pnOHNnjyahYiEAydvpGotq2QtwR40APheoTPNWj/XjCl4lDjcY1 VHnIBX1bmsIt1weNmyHrdcB8oP/nZo1A7keHz6zinmge7xV3rg== X-Google-Smtp-Source: AA0mqf6iY3zu3plqeqJpaFmjxbVu1nLMbR/ti4+eErEDqg3F1P8OeCOi/K9hEyfu4oWw0nyweYL6ttyCuKwtxvpWSjk= X-Received: by 2002:a17:906:f20f:b0:7aa:23ac:608e with SMTP id gt15-20020a170906f20f00b007aa23ac608emr15494170ejb.450.1668563401738; Tue, 15 Nov 2022 17:50:01 -0800 (PST) MIME-Version: 1.0 References: <6a92000c-dee5-a1e3-a77f-6a4697a66ab1@eastlink.ca> <34a949c4-0853-4c65-d2ad-db40749dff81@eastlink.ca> <2dd50dc8-cdbc-02e0-0e1e-485718732d0d@eastlink.ca> <3a10f310-3ee8-d3b4-f6db-7fdb18b81b1f@eastlink.ca> <77692192-70b3-8a6a-fd01-d5f8b37f59b2@eastlink.ca> <879a8fb0-74b7-5250-d2ff-2f60585f48a4@eastlink.ca> In-Reply-To: <879a8fb0-74b7-5250-d2ff-2f60585f48a4@eastlink.ca> From: Bart Schaefer Date: Tue, 15 Nov 2022 17:49:50 -0800 Message-ID: Subject: Re: Belaboring substitution syntax To: Ray Andrews Cc: zsh-users@zsh.org Content-Type: text/plain; charset="UTF-8" X-Seq: 28389 Archived-At: X-Loop: zsh-users@zsh.org Errors-To: zsh-users-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-users-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: On Tue, Nov 15, 2022 at 6:18 AM Ray Andrews wrote: > > I sorta get that '[@]' is saying: "process this array line by line" thus preserving array indexes. I'm not sure about the quotes. This follows the same rules as $@. If you write "${array[@]}" with the quotes, you get each element of the array separately quoted. This often doesn't matter in zsh but always matters in other shells or when SH_WORD_SPLIT is enabled in zsh. BTW you need to stop thinking of these as "lines" -- line breaks have nothing to do with it. Conversely if you write "${array}" or ${array[*]}" either one with the quotes, you get the entire array joined into a single string. > and sometimes the quotes seem to protect stuff from expansion or interpretation: Quotes ALWAYS protect SOMETHING from expansion or interpretation, unless you start throwing other things in there such as eval. WHAT is protected differs: Double quotes allow ${param} and $(process) and $((math)) replacements but protect syntax tokens and glob patterns and whitespace; single quotes protect pretty much everything. > In my case, leaving the quotes out doesn't *seem* to matter but I know it would bite me eventually. When would it bite me? In the specific example in this thread, zsh's default array behavior (no_SH_WORD_SPLIT) is sufficient, but if you later enclose that or a similar construct in a deeper context, yes, you might be bitten. > Do we not have an operator that says (in English): If string A is a substring of B, then return B, else return nothing. Your trouble is the definition of "nothing." ${B:#*A*} does that, but in your example here, you don't actually want "nothing", you want "the empty string" which is still something. In fact the example in question is "if A is NOT a substring of B then return B, else return the empty string." So we have this: Do a replacement on every element of $cc is ${cc[@]/...} Replacement must start at beginning of element ${cc[@]/#...} Replacement must also end at end of element ${cc[@]/#%...} Use $zsh_case as a pattern is $~zsh_case Match that pattern anywhere with $filter is *$~zsh_case${filter}* Match NOT that whole pattern is ^*$~zsh_case${filter}* Put it all together: ${cc[@]/#%^*$~zsh_case${filter}* Replace all that with the empty string is just close the brace ${cc[@]/#%^*$~zsh_case${filter}*} ... and then the double-quotes for safety. About the only thing your magical operator could remove is putting *...* around the pattern to mean "is a substring".