From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.2 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,HTML_MESSAGE,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham autolearn_force=no version=3.4.4 Received: from zero.zsh.org (zero.zsh.org [IPv6:2a02:898:31:0:48:4558:7a:7368]) by inbox.vuxu.org (Postfix) with ESMTP id 5EAE024109 for ; Sat, 13 Apr 2024 22:12:30 +0200 (CEST) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1713039150; b=mNsF0uev5NELSWSvBAPMk+DdMcV9JBd5uqepKemJQyGvyz25O/LPfj/dC1ulD7o2s3CZrgft8P tUIa0PhfkAko3jW6dXdLEGRh1NgZY54lq6Pat5PAgGoDl48KdQ9OXsKAqmCkFxE39Y9VlkPdtH g1I/t2ybd7TJ/SY3aiMEHn97CVMsb0PnmfeWNAJF4PAkzxCIyg1V+1+LokWuq/Zwe3HTxFgHYz ln/sesFVS8PoDYola7W+NgDFbIkVkPA3WPA7qoklntv9rTOVejBqTLxdGlI9L9WYqM/wBqJfiZ /ir930ghxZb1ZUbJG5k+aDihdXGokAIT3wM/Y24m2eDrRA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lj1-f179.google.com) smtp.remote-ip=209.85.208.179; dkim=pass header.d=gmail.com header.s=20230601 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1713039150; bh=CA3ZPL8emc6HPJyeUGC56Qi01Vrg5mC0V7c7P8VL9kg=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=ANXIcefpIfpdKF877bdo5Rpl4yuKuLqL2tvUOwEMJDdMzJPlskNxlbmjjHX7Davu0PiBhifnbp sFJqSdSwa2CQ0zQXFvMEG3PAZMDO493Mflxri1PhUvkZDKKNCBcbjBX0pmP8xzahiuIDnldNTv wh3QG3Ipi7ax/HsBGLYn/OW63aKIOqu0T31PTrUKSsEHaYYPJ1MGmHnPe0VPE12Yrwnm3GD8YE adxyQl79BtonylqOKi4pSzBd/ETEdj/afWInsMa3fIyujiKQut0hcN7/3lMebphkp6iN8Wgoul lR2lNn26Mmv+901TFWT68tnlE0n3k8u/5iF07dbGMd7pEw==; 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:To:Subject:Message-ID: Date:From:In-Reply-To:References:MIME-Version:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=d0eTV8HwwpOw95ZxK7ODimXVUL/ZH2er4cdORND20Ec=; b=nAjjqfhmedfQLAg3iWzEtVqmea 3SCUJd+EySko7mMFbsZWzCzNbescPkLpIiqp+hAqO5ymWKhW8MMMY8ulMN9WWpTawAlaSXCeCb6Nn /HoijjUptU6uAbZbZMZylAAed/bKkwOd/0Jwf5Iu9T/pCw6+28GONXOBNu/nYcZ4DP6CkrUYo6tjI RyxEak09mMNS+0lVNcG0mRPQ2PcvF/ZpdNWS9NwRxHbp7FWRG6uyGTDOpX8d4uiHu0ZrjFnsoP0XK k8cHo+3zefvenL/MPokA+fWuU0VquRuLFGsX3qoyCPuTWyqzeeZjt6mgfAt2GX9QbUW5FSO6XOHqt 8QxkdMQg==; Received: by zero.zsh.org with local id 1rvjji-000Pc0-O9; Sat, 13 Apr 2024 20:12:30 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lj1-f179.google.com) smtp.remote-ip=209.85.208.179; dkim=pass header.d=gmail.com header.s=20230601 header.a=rsa-sha256; dmarc=pass header.from=gmail.com; arc=none Received: from mail-lj1-f179.google.com ([209.85.208.179]:57506) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rvjjD-000OvK-5q; Sat, 13 Apr 2024 20:12:00 +0000 Received: by mail-lj1-f179.google.com with SMTP id 38308e7fff4ca-2d87450361fso23831871fa.2 for ; Sat, 13 Apr 2024 13:11:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1713039118; x=1713643918; darn=zsh.org; h=to:subject:message-id:date:from:in-reply-to:references:mime-version :from:to:cc:subject:date:message-id:reply-to; bh=d0eTV8HwwpOw95ZxK7ODimXVUL/ZH2er4cdORND20Ec=; b=hmMDmq5hjvF/63Wc8WGne/VIHWzQE/QQbT4aHoRgFP8d+xsgMyvsqUYT1/3x6YX1vv fR/Dc9lkJZFVf3ETiSp3MNgS4ctWhKslMpuUgLZGVXV56np834IDba++Um5NCm9E39mw IZIKAbQYKPRvX+vU14q3uOBX9zElf/w2iHK23VBh5YKxoqMntf4cDjMdfEGNhbla0ju2 P6TvKctBSDb+Qgez4+iFW5FoEtj7fudYCDiaEuUDHToBKCrQHDTh8QEhFclwbm67xn8D ezNOi65YngeIpzgM8gM9Sq7m7GQndxqiE1SIo+KathelgjXalw91EQihcPALYsb4VlFn lkzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713039118; x=1713643918; h=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=d0eTV8HwwpOw95ZxK7ODimXVUL/ZH2er4cdORND20Ec=; b=b53s+wVaPnDgvskIov3QJ+FFJG/tDe9ztmXssn1CPs0oRLFhPSm0K9RCnAJ952tvkT Hz3xv07vujytdx5Du7RE4OffZrwQN0LwTGvP4BEXwh0l4cSKQG2quKfFltmpHBCHGnPo YTrkvxbygn6NkLhAiHYFHwJkacOJ2iz9QVNk6mFk++tKs64I0ibKvu9V4ynNFNI7rjVF C8FyCknZeEXO2aePCUJObXM49niqV+qxIwIoOoHMIym6kebkWPuW5M24ft9XqWJFVrly 75FEH0hZ3yoshhldmtjZeD0Xjf7AxWAg1sPyc6E3uwXX4r6LSx+iuvaGt4BUfj3pjiXh MRMg== X-Gm-Message-State: AOJu0YwrlEISNKUsF2EatcNend9CKXluVmpAH+zC6o2SF3qHPlBB+0qS Px7PVckapGGWaEZCATI8SSDaMthWZye9Q196Oa2wIoVT8oaBTUtYrG8wICs3bDLCo+5h8Ez3hht TQSWamT7b7T05Mop/4FcCTfL7PhndcseUPDI= X-Google-Smtp-Source: AGHT+IGP4kx/a+Wn4kyuDpZAvoRLNHwAqyeReRyY8L4IefuVAQEWLH+i3g3OKMNa/SETFXnFriWpMAV0yPiCrelNWu0= X-Received: by 2002:a2e:9942:0:b0:2da:5069:b31f with SMTP id r2-20020a2e9942000000b002da5069b31fmr660701ljj.20.1713039117448; Sat, 13 Apr 2024 13:11:57 -0700 (PDT) MIME-Version: 1.0 References: <97793422-1543-4ba6-b52b-ff93eba03ab1@eastlink.ca> <7ba17739-6024-439b-a4a7-dd88fddfa2e4@eastlink.ca> <7333cf23-1fe7-4b3d-a7c1-f07697c5f062@eastlink.ca> <1e53a3f7-9bdb-45ae-81c7-7d0ec1a6a541@app.fastmail.com> <3cc19e86-e953-4e2f-9e57-30ff84f15fdf@eastlink.ca> <0a0b9ec3-4661-4386-9fbf-b3152a46001e@eastlink.ca> In-Reply-To: <0a0b9ec3-4661-4386-9fbf-b3152a46001e@eastlink.ca> From: "Mark J. Reed" Date: Sat, 13 Apr 2024 16:11:44 -0400 Message-ID: Subject: Re: triviality regarding $# counts To: zsh-users@zsh.org Content-Type: multipart/alternative; boundary="00000000000014ffac06160000f7" X-Seq: 29808 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: --00000000000014ffac06160000f7 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable There still seems to be some confusion, so I'm going to back up a bit. Apologies in advance if I tell you something you already know. Quotes are part of the shell syntax. They aren't part of the quoted value. If you do this: name=3D'Ray' then the value stored into the variable *name* is just 3 characters: *R*, *a*, and *y*. There aren't any quotes anymore; they were just there long enough to tell the shell that you want the characters in between them to be taken literally. In this simple case, they aren't even needed; this has exactly the same result: name=3DRay It's important to keep the distinction in mind between the *values* you're working with and the particular way you represent those values in the *syntax* of the language. Here's an example where the quotes are actually required: multiline=3D'hello, there' The above command is two physical lines of text, but only one shell command, and that command is assigning one string value. The result is not an array; it's a single, scalar parameter containing 12 characters, one of which happens to be a newline: *h*, *e*, *l*, another* l*, *o*, a comma, a newline, *t*, *h*, *e*, *r*, and finally another *e*. You can access all of them with subscripts; *$multiline[1]* is *h*, *$multiline[2]* is *e*, etc. The quotes, despite being required, are still not part of the value. The ability to do this also highlights the fact that newline is just another character. Just like a letter of the alphabet or a digit or a punctuation mark, it's just a number, but in the context of text that number is interpreted as a character. The number 65 means *A*, 44 means comma, 48 means *0*, and 10 means newline. After the above assignment, the newline may be found at *$multiline[7]*. Here's another way of assigning exactly the same value to the same variable= : multiline=3D$'hello,\nthere' Here we have a single-line command assigning a multiline value. The ANSI quotes *$'*...*' *let us use the ANSI C escape sequence *\n* to mean a newline. The result is the same: the value of *multline* is 12 characters long, and *$multiline[7] *is a newline. This assignment gets you something completely different: oneline=3D'hello,\nthere' Now there is no newline character anywhere in the string. It's 13 characters long, not 12; *$oneline[7] *is not a newline but a backslash, and *$oneline[8]* is an *n*. After the above pair of assignments, you might be confused by the fact that *echo $multiline *and *echo $oneline* produce the same result, but that's because *echo* is doing the same kind of translation of ANSI C escapes that the shell does when you use *$'*...*'* quotes. If you turn that off by using *e= cho -E*, then you'll get two different answers: $ echo -E "$multiline" hello, there $ echo -E "$oneline" hello,\nthere (I used double quotes above out of long habit; they're not strictly necessary, especially not in zsh.) A pair of quotes =E2=80=93 of any variety, single, double, or ANSI =E2=80= =93 with nothing between them represents the empty string. The empty string is nothing at all; if you print it out by itself, it's the same as not even executing the print command. Despite this, it is sometimes a useful thing to store in a variable: empty=3D'' After the above assignment, *$#empty* is 0. It literally contains nothing. Again, you don't actually need the quotes; this also works: empty=3D Which reinforces the role of the quotes as syntax rather than value. And again, an empty string is not an empty *line. *If, when you print out the empty string, you do so with a command that adds a newline at the end, the *output* will be an empty line, but it's the printing that makes it a line. The value inside the variable has no line-ness. On Sat, Apr 13, 2024 at 2:08=E2=80=AFPM Ray Andrews wrote: > On 2024-04-13 10:27, Mark J. Reed wrote: > > Small followup I meant to type but didn't: > > On Sat, Apr 13, 2024 at 1:19=E2=80=AFPM Mark J. Reed wrote: > >> redline *'\nddd=3D( "${(@f)aaa}" ) ... it seems like a lot of trouble to >> copy the array as it is.'* >> >> >> That comment confuses me; you aren't copying the array as it is at all! >> You've gone from *aaa, *which has one element, to *ddd *having 8 >> elements. That's a far cry from "copying as it is". >> > Ah, but Mark, I figured all that out by the bottom of the post. At that > point I was still laboring under 'visual thinking' . I dare say I'm > straightened out. I had thought that 'split on newlines' meant 'add \n's > where needed to demarcate element boundaries'. It's actually sorta the > opposite -- there is no demarcation character and \n's will in fact be > removed. But I'm still not happy with the dollars. I had thought that " > $'...' " was grammatical but we have " ' ' " -- meaning an empty line = -- > without the leading dollar, so the closest thing I could pattern was that > they replaced the newlines. If anyone on the planet can get it wrong, > it's me. > > > --=20 Mark J. Reed --00000000000014ffac06160000f7 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
There still seems to be some confusion, so I'm go= ing to back up a bit. Apologies in advance if I tell you something you alre= ady know.

Quotes are part of the shell syntax. The= y aren't part of the quoted value.=C2=A0 If you do this:
=
<= div>name=3D'Ray'

then the value stored into the variable n= ame=C2=A0is just 3 characters: R, a, and y.=C2=A0 = There aren't any quotes anymore; they were just there long enough to te= ll the shell that you want the characters in between them to be taken liter= ally. In this simple case, they aren't even needed; this has exactly th= e same result:

name=3DRay=

It's important to keep th= e distinction in mind between the values you're working with and= the particular way you represent those values in the syntax of the = language.

Here's an=C2=A0example=C2=A0where th= e quotes are actually required:

multiline=3D'hello,
there'

The = above command is two physical lines of text, but only one=C2=A0shell comman= d, and that command is=C2=A0assigning one string value. The result is not a= n array; it's a single, scalar parameter containing 12 characters, one = of which happens to be a newline:=C2=A0=C2=A0h, e, l, = another l, o, a comma, a newline, t, h, e, r, and finally another e. You can access all of them with = subscripts; $multiline[1]=C2=A0is h, $multiline[2]=C2= =A0is e, etc. The quotes, despite being required, are still not part= of the value.=C2=A0

The ability to do this also h= ighlights the fact that newline is just another character. Just like a lett= er of the alphabet or a digit or a punctuation mark, it's just a number= , but in the context of text that number is interpreted as a character. The= number 65 means A, 44 means comma, 48 means 0,=C2=A0and 10 m= eans newline.=C2=A0 After the above assignment, the newline may be found at= $multiline[7].

Here's another way of a= ssigning exactly the same value to the same variable:

<= div>
multiline=3D$'hello,\nthere'

Here we have a sin= gle-line command assigning a multiline value. The ANSI quotes $'= ...' let us use the ANSI C escape sequence \n=C2=A0to mea= n a newline. The result is the same: the value of multline=C2=A0is 1= 2 characters long, and $multiline[7] is a newline.

This assignment gets you something completely different:
=
oneline=3D'hello,\nthere'<= /div>

Now there is no newline character an= ywhere in the string. It's 13 characters long, not 12; $oneline[7] <= /b>is not a newline but a backslash, and $oneline[8]=C2=A0is an n= .=C2=A0=C2=A0

After the above pair of assignments, y= ou=C2=A0might be confused by the fact that echo $multiline=C2=A0and = echo $oneline=C2=A0produce the same result, but that's because <= b>echo=C2=A0is doing the same kind of translation of ANSI C escapes tha= t the shell does when you use $'...'=C2=A0quotes. If = you turn that off by using echo -E, then you'll get two differen= t answers:

$ echo -E "$multiline"

hello,

there

$ echo -E "$oneline"=C2=A0 =C2=A0

hello,\nthere


(I used double quotes above o= ut of long habit; they're not strictly necessary, especially not in zsh= .)

A pair of quotes =E2=80=93 of any variety, sing= le, double, or ANSI =E2=80=93 with nothing between them represents the empt= y string. The empty string is nothing at all; if you print it out by itself= , it's the same as not even executing the print command. Despite this, = it is sometimes a useful thing to store in a variable:

=
=
empty=3D''

After the above assignment, $#empty=C2=A0is 0. It= literally contains nothing.=C2=A0

Again, you don&= #39;t actually need the quotes; this also works:

=
<= font face=3D"monospace">empty=3D
= =C2=A0
Which reinforces the role of the quotes as syntax rather t= han value.=C2=A0

And again, an empty string is not= an empty line. If, when you print out the empty s= tring, you do so with a command that adds a newline at the end, the outp= ut will be an empty line, but=C2=A0it's the printing that makes it = a line. The value inside the variable has no line-ness.

On Sat, Apr 13, 2024 at 2:08=E2=80=AFPM Ray Andrews <rayandrews@eastlink.ca> wrote:
=20 =20 =20
On 2024-04-13 10:27, Mark J. Reed wrote:
=20
Small followup I meant to type but didn't:

On Sat, Apr 13, 2024 at 1:19=E2=80=AFPM Mark J. Reed <markjreed@gmail.com> wrote:

redlin= e '\nddd=3D( "${(@f)aaa}" ) ... it seems like a lo= t of trouble to copy the array as it is.'


That comment confuses me; you aren't copying the array as it is at all! You've gone from aaa, w= hich has one element, to ddd=C2=A0having 8 elements. That's a far cry from "copying as it is".
Ah, but Mark, I figured all that out by the bottom of the post.=C2=A0 A= t that point I was still laboring under 'visual thinking' .=C2=A0= I dare say I'm straightened out.=C2=A0 I had thought that 'split on ne= wlines' meant 'add \n's where needed to demarcate element boundaries= 9;.=C2=A0 It's actually sorta the opposite -- there is no demarcation character and \n's will in fact be removed.=C2=A0 But I'm still not happy wit= h the dollars.=C2=A0 I had thought that "=C2=A0 $'...'=C2=A0 &qu= ot;=C2=A0 was grammatical but we have " ' ' "=C2=A0 -- meaning an empty line -- withou= t the leading dollar, so the closest thing I could pattern was that they replaced the newlines.=C2=A0=C2=A0 If anyone on the planet can get it wrong, it&= #39;s me.=C2=A0




--
Ma= rk J. Reed <mar= kjreed@gmail.com>
--00000000000014ffac06160000f7--