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.3 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,T_SCC_BODY_TEXT_LINE 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 717A828D70 for ; Wed, 14 Feb 2024 16:59:26 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1707926366; b=Lf+xNIZdVbxj1aUif7QbudjhgVwQ68Y94SCSejdDqU7BcDhIulJ/F4AJdic3UrhOW8V7u3/Lza 2Vlea+mb+59icIDyNXopQlUJ7xXRbSqFVKZkSNzpyE1IknBpN7NUoQgKdXVphbLX5PBpjnDvhp 0sASihK+LqCPZM0LVXvZNECm9ujCi1yJTKgNquMLEcEC5iCiIha9SwLHSUmmEUnB4N5YctAXv2 cIcv8ciQSl9FF/GcF83//5Qp68JAAaPRPDAU8Akrpdp4gczaaC2hTehQC23h5dlGYwgsxiIjoG b1ryme5V2EA6psDfT1fnmCXXl4s/BQF3DffGLTQCCR274g==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lj1-f181.google.com) smtp.remote-ip=209.85.208.181; 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=1707926366; bh=rqYot3o458Y1h5tDyxmpjAwKP9DqRWna8sGeA7sxgoI=; 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=ca1yy6cTfbUVtw2FlZYAhw+Ge62o1nvubE1Ju7LZoSVtBqJxiZA+3ctNKP7G6w75bVt6u2Ahr3 BORNoaundk2Q1QKGXH9CPLDRKMMpTFLpD/vB1l8BBoKOnx40b1ujMwIfKkpmzLg01Zi7I3URTY fFm39KteRrdXWL1JXHHcRBaQmVeyq4ji/dZ+T/s5IZ66sepvPx4JW4u3kHoaC0i6VyOyQ/07iu 39ACoQpBVIyTWbxo1mQrPycmv1Tm0J6QAA5UDKx240cGoVxE7mzuwcyneEe13hCOZ0h+Y9Msla Mrux30apvHkz7I5781eZWLzRqMJEu7mOLEnbCzyi44ED7g==; 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=tfGeTajLOLxf0z7DEua4JOIDrcjF4QGTHFOuMr4rJnE=; b=bFNpUIe/cbvNO89bIvepAjEDTD PEOMJli5ua32ILfT7Nj6bINDZLVwMaT8i7FttUqmJmLu3pJyvNLzVnqTGfn75P8HOepY7pEw8zkYo PUllnxYJ7C9VxSBhYuuOZfPhOYHK3PPCa8LtqEKNbopulLWVjLmHg0lEeZ6H1DgHv51fWhn3omkEQ g8rAMCBwJoVOsznQGBYv4yi865m7JtStmR15sxIcQKt2MT7y7Ql53Vf2hRW1KBdHvJ7yPGMhBSE7s dwIw/NfjrfQCGQiuTCPjE0jjBm2fr7TevKZFmre9B+bJq/EwjE0EV6rUeTph+X0DjIhmNTz8pPfAz r8aFtEAg==; Received: by zero.zsh.org with local id 1raHfR-0001a7-Ti; Wed, 14 Feb 2024 15:59:25 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lj1-f181.google.com) smtp.remote-ip=209.85.208.181; 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-f181.google.com ([209.85.208.181]:53590) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1raHev-0000tb-TZ; Wed, 14 Feb 2024 15:58:55 +0000 Received: by mail-lj1-f181.google.com with SMTP id 38308e7fff4ca-2d090c83d45so72907201fa.3 for ; Wed, 14 Feb 2024 07:58:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1707926332; x=1708531132; 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=tfGeTajLOLxf0z7DEua4JOIDrcjF4QGTHFOuMr4rJnE=; b=m5n7x6EKnD+qqZXvaVuUmplkrz1n1MKV5ckm6P8GNOkAKjAE6x4UwLgdM/0eOHEWRP spDXUsdmDP302VhEX2A9Nzc77U7QrfQlxUrMoWlmUOpllJBMi/h4qadgia7zF1pIyaE4 53EolqMcROlSfm3+jmnj/HFjvIUUfxRHSqBVcxQD9hnD7uDT2zIN6AvNR1lJ0Jsr2xIT 8aR1vvSXi45KGxgp6RRn9BzH+26icu0xuB79Yz8TOAxfAVaK+UMLluDdqszYsGUlIrOI 0WgzwCn3xn67ZFhGtV6u86opdecT+ehaOdS+XCzZhisDUounUFbmLX6VF9FnZB8+Nyjy kiIg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1707926332; x=1708531132; 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=tfGeTajLOLxf0z7DEua4JOIDrcjF4QGTHFOuMr4rJnE=; b=m6clj8sauIDXzN+Po6zQGTN6Q1O4fiHpH2GOQuscA8AmAkDvhvZS3IE8GFcFzbCLWN kbIcvsHzfBM82W1y8JwRN71et8s8HExxU6crM8QAjvW9Y2ZlVNEMuoQS8ytlqS3ICSZ/ MTuOsxu5/ITnQigvrjBVMlfd6HMEQFk7Ko4DP8XDLOBNkWNFSzYgefiR8MU1WcqCtcqF 7yx8cov9siTosI1f3F58+/q+tYjIPqp1HZQ7DrUzYG34G4GTGXXXl9yB1kJK+RJFN7Nw ziJSkoyn7MrSXdm7wDcD/gbVlJOVbUYRk6Jxv7tsnaZ6xe9JHxIZq7ROB+0v8NzVuKPt 6zdQ== X-Gm-Message-State: AOJu0YxZJDyq7T2ytw76CycgNyn5ZE+EQEhu0st13/R/AZTavdFV16Sd +CGQ/beeHL4HI0kXjHhQYNwPpN4sAKu1Amir7DOKfvBbiZ2W2kkRBGpPFUIFhgqzcvGcgbEBiYf xeeoj/Q/w/IvpARSNoZTwqC6hQJKbitAfz6c= X-Google-Smtp-Source: AGHT+IFDrl8FW5XCP0fIzlu8cg6JFWJfkXoVM+SMrBXXh8OE0pt3WK+0MERLMJIKJ46MfrN2gwnQLnhM/1ZPC+7G+NY= X-Received: by 2002:a2e:86c4:0:b0:2d0:b70a:a947 with SMTP id n4-20020a2e86c4000000b002d0b70aa947mr2358593ljj.23.1707926332221; Wed, 14 Feb 2024 07:58:52 -0800 (PST) MIME-Version: 1.0 References: <0b3cf56b-004d-4a9f-a643-a53ccb50e278@eastlink.ca> In-Reply-To: <0b3cf56b-004d-4a9f-a643-a53ccb50e278@eastlink.ca> From: "Mark J. Reed" Date: Wed, 14 Feb 2024 10:58:39 -0500 Message-ID: Subject: Re: Counting characters in command output? To: zsh-users@zsh.org Content-Type: multipart/alternative; boundary="00000000000055adb006115996c7" X-Seq: 29670 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: --00000000000055adb006115996c7 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable > I myself almost always want lines. Or elements. Sometimes words, almost never characters. As I said, it's the consistency. If you have a scalar parameter named *foo*= , *$#foo* is the number of characters. If it's an array, *$#foo* is the number of elements. The key point in my mind is that when you assign a parameter from command substitution, e.g. *foo=3D$(bar)*, then what you get is a scalar parameter, not an array. You *can* get an array instead, but you have to ask for it explicitly by putting extra parentheses around the right hand side: *foo=3D($(bar))*. So parameter assignment defaults to scal= ar mode and requires extra punctuation to do array mode. But directly counting the result of the substitution with no intervening parameter defaults to array mode and requires extra punctuation to do scalar mode. On Wed, Feb 14, 2024 at 10:37=E2=80=AFAM Ray Andrews wrote: > > > On 2024-02-13 22:49, Roman Perepelitsa wrote: > > Right, command substitution. In my opinion, it's unfortunate that > > command substitution in zsh splits on IFS by default. I wish this > wasn't the case. It's not even common that one wants to split command > output into words. Lines -- perhaps, but not words. So the default > behavior in this case is rarely what is desired and has to be actively > turned off. > > What are the vectors? First must be logical necessity, second consistenc= y > -- avoid strange exceptions -- third and fourth would be helpfulness and > tradition, with old-school guys favoring tradition and guys like me > favoring helpfulness. I've spent more hours trying to get splitting issu= es > correct than anything else. Characters, words, IFS, lines, elements ... > it's the most obscure and confusing part of the shell. Lacking any > focused explanation of the entire subject what I do is just throw saved > snippets of code at problems until something sticks -- it looks about > right, but even there I might think I have line splitting when it's reall= y > elements. I wish there were enough of us on this list to put things to a > vote sometimes and in this case I'd bet that Roman's view would win > overwhelmingly. I myself almost always want lines. Or elements. > Sometimes words, almost never characters. > > > > --=20 Mark J. Reed --00000000000055adb006115996c7 Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable
> I myself almost always want lines.=C2=A0 Or elements.= =C2=A0 Sometimes words, almost=C2=A0 never characters.

A= s I said, it's the consistency. If you have a scalar parameter named=C2= =A0foo, $#foo is the number of characters. If it's an arr= ay, $#foo is the number of elements.=C2=A0 The key point in my mind = is that when you assign a parameter from command substitution, e.g. foo= =3D$(bar), then what you get is a scalar parameter, not an array. You <= i>can get an array instead, but you have to ask for it explicitly by pu= tting extra parentheses around the right hand side: foo=3D($(bar)). = So parameter assignment defaults to scalar mode and requires extra punctuat= ion to do array mode. But directly counting the result of the substitution = with no intervening parameter defaults to array mode and requires extra pun= ctuation to do scalar mode.


On Wed, Feb 14, 2024 at 10:= 37=E2=80=AFAM Ray Andrews <ray= andrews@eastlink.ca> wrote:
=20 =20 =20


On 2024-02-13 22:49, Roman Perepelitsa wrote:
Right, c= ommand substitution. In my opinion, it's unfortunate that
command substitution in zsh splits on IFS by default. I wish thi=
s
wasn't the case. It's not even common that one wants to split comma=
nd
output into words. Lines -- perhaps, but not words. So the default
behavior in this case is rarely what is desired and has to be actively
turned off.
What are the vectors?=C2=A0 First must be logical necessity, second consistency -- avoid strange exceptions -- third and fourth would be helpfulness and tradition, with old-school guys favoring tradition and guys like me favoring helpfulness.=C2=A0 I've spent more hours = trying to get splitting issues correct than anything else.=C2=A0 Characters, words, IFS, lines, elements ... it's the=C2=A0 most obscure and con= fusing part of the shell.=C2=A0 Lacking any focused explanation of the entire subject what I do is just throw saved snippets of code at problems until something sticks -- it looks about right, but even there I might think I have line splitting when it's really elements.=C2=A0 = I wish there were enough of us on this list to put things to a vote sometimes and in this case I'd bet that Roman's view would win overwhelmingly.=C2=A0=C2=A0 I myself almost always want lines.=C2=A0 Or= elements.=C2=A0 Sometimes words, almost=C2=A0 never characters.





--
Ma= rk J. Reed <mar= kjreed@gmail.com>
--00000000000055adb006115996c7--