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.1 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_EF,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 00A8722224 for ; Fri, 12 Apr 2024 16:49:49 +0200 (CEST) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1712933389; b=NSH5b60Pb06h7YlPmcxWCxryUOsGof6Mf4f1GMea0yNG22TdRLrMllnOWCaJCRAvJ5tLTXH2qF QX7Si+vjtvW+OOJIx5lAU0g46CxMBZtnVZumvKORVMfjJgyKb1z55CTxIDYOmHBgKzaDv80lJa Uh9mIXXZicsxvqw9i1Bw8rnMoprUfQYZCuE+zPe4GgChIgq72m7JZZi86hUHZA14sQBHrmjwIc T1n6ZU7wcFi2mepUljLUXzDCKsondtCs72Hu6CIm7EN1jQX/4RIlluX1qTUAExqMsRYVmb3ajl e5qe2wkl4uMGu74cA9GhqUwczdYqvn6c68eJoCh25UWy1Q==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mta01.eastlink.ca) smtp.remote-ip=24.224.136.30; dmarc=none header.from=eastlink.ca; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1712933389; bh=/CMChgQQANyOuaxDRoABZJys0kdO6qLjUFqvyFWWrj0=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:From:References:To:Subject:MIME-Version:Date: Message-ID:Content-Type:DKIM-Signature; b=laeXvl6PvlW71fTlP7xu4KgNmWpOcSb5Ni+P+bM8dKXbWkS8DyM/1DswMz4Ktiw/2pL+L76H8q O7W5RnL4y4iLIcbkQIPv8XhMwB3EMYoBCeB2qTEydWxPw762P1ka6+i1Pn+s8ZCUgXdOg4qPV5 JoLslS0PpSVsJva/JGKn1InI449UfwndPepNsBf3ufsm9f09oKJ1SYlgXV0XGk+/bQR2j2GrVB TW7GNVOOim2VaVoG/Iqm1/pfEK5TmHf1ZAL6AfHT7JM9GjhW6TtNxGhYRki+qoxZ0FkULo5n9X Ds1akR7y0hbybh7bknBBGtD9+eMtIrnOVf+68z16W7xBuA==; 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:In-reply-to:From:References:To: Subject:MIME-version:Date:Message-id:Content-type:Reply-To:Cc: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=cdD5SZ5ZSsdluBJYJOA5+Zt16az2+MLno0oqFnqcH7M=; b=pbgJYohx+QZJ3gh6+dP8n9fevC 1AeOqKhdugczG+F/xupHX/tIF8AGp2DvJwg5Q4nuYlPHeDEI+8uKfCJTkxDvjavVZd43nOO3N9RGr atrVaFgVVUC0t37luTronnB2z5jBkLxiYC0tJhfkHqIMd7neSjxf70mIfUuTWLaSql64p6k6Dd6Rk j8WELaGoXFeQsuXjWlksqxjfuDrLI3x5vnPRUPDXxh7QHQ/TGDCQzcqhAssSXcyLE4ZYEE2KCzy7K eJbwkPdi62dRnwNM3nBknWbWPFi5zPA2YtEsFsZRph9LN2jUCGm3+bgaHQBtvvZX/7J+ahIh5fIbP pFsWZfKw==; Received: by zero.zsh.org with local id 1rvIDs-000JUt-TA; Fri, 12 Apr 2024 14:49:48 +0000 Authentication-Results: zsh.org; iprev=pass (mta01.eastlink.ca) smtp.remote-ip=24.224.136.30; dmarc=none header.from=eastlink.ca; arc=none Received: from mta01.eastlink.ca ([24.224.136.30]:60059) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rvICz-000Ijc-DD; Fri, 12 Apr 2024 14:48:55 +0000 Received: from csp01.eastlink.ca ([71.7.199.166]) by mta01.eastlink.ca ([24.224.136.30]) with ESMTPS id <0SBU034WB3MCJ0G0@mta01.eastlink.ca> for zsh-users@zsh.org; Fri, 12 Apr 2024 11:48:51 -0300 (ADT) Received: from [192.168.0.11] (host-24-207-19-13.public.eastlink.ca [24.207.19.13]) by csp01.eastlink.ca ([71.7.199.166]) with ESMTPSA id vICxrqPjJAimnvICxr0oQj (version=TLSv1_2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256); Fri, 12 Apr 2024 11:48:51 -0300 X-Authority-Analysis: v=2.4 cv=Q8Rx4J2a c=1 sm=1 tr=0 ts=661949d3 a=e7T7DzMKK1R988ZCg0wLyw==:117 a=e7T7DzMKK1R988ZCg0wLyw==:17 a=r77TgQKjGQsHNAKrUKIA:9 a=kiZX2H4ukMK-ClN3DfgA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=ZLGELXoPAAAA:8 a=aagz_gqIemczdj47ZXYA:9 a=4XTvdzKPwcOwkUR_:21 a=_W_S_7VecoQA:10 a=CFiPc5v16LZhaT-MVE1c:22 X-Vade-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudeiuddgkedvucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecugfetuffvnffkpffmpdfqfgfvnecuuegrihhlohhuthemuceftddtnecunecujfgurheptgfkffggfgfuvfhfhfgjsegrtderredtvdejnecuhfhrohhmpeftrgihucetnhgurhgvfihsuceorhgrhigrnhgurhgvfihssegvrghsthhlihhnkhdrtggrqeenucggtffrrghtthgvrhhnpefhteethfevgeeuvdelgefgvdevudefueduffdvgfelvddvgfdtieegueeuleeifeenucfkphepvdegrddvtdejrdduledrudefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepvdegrddvtdejrdduledrudefpdhhvghloheplgduledvrdduieekrddtrdduudgnpdhmrghilhhfrhhomheprhgrhigrnhgurhgvfihssegvrghsthhlihhnkhdrtggrpdhnsggprhgtphhtthhopedvpdhrtghpthhtohepreerpdhrtghpthhtohepiihshhdquhhsvghrshesiihshhdrohhrghdpghgvthdqkghiphfrrghsshifugepthhruhgv X-Vade-Score: 0 X-Vade-State: 0 X-EL-AUTH: rayandrews@eastlink.ca Content-type: multipart/alternative; boundary="------------nKhLZWIxpAjzpnKE8osdFfiC" Message-id: Date: Fri, 12 Apr 2024 07:48:50 -0700 MIME-version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: triviality regarding $# counts To: zsh-users@zsh.org References: <97793422-1543-4ba6-b52b-ff93eba03ab1@eastlink.ca> Content-language: en-US From: Ray Andrews In-reply-to: X-Seq: 29795 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: This is a multi-part message in MIME format. --------------nKhLZWIxpAjzpnKE8osdFfiC Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 2024-04-11 21:55, Lawrence Velázquez wrote: > If eval really is necessary (to be frank, I don't trust your judgment > on this), show us examples that require it, instead of the misleading > Rube Goldberg machines you've been offering. I don't trust it neither, and I taught Rube everything he knows. Seriously, you won't sympathize, but the tinkerer's approach was the only one available to me at least until I had enough ad hoc code built up that sorta works to begin to start to try to understand it formally.  And my efforts to find patterns of behavior -- as you know better than anyone -- lead me to false conclusions all the time.  The manual is useless as pedagogy.  If there was 'zsh school' I'd enroll and learn my shell ABC's properly from the ground up. But there isn't.  So I hack away.  But please understand I *hate* being me.  I like competence :( > The count is correct by accident. Your unquoted command substitution > drops the two empty lines but splits the two lines you say should not > be split. Right, I'm aware of that possibility at least in theory.  Word splitting lurks. > % orig='abc > quote> > quote> def ghi > quote> jkl mno > quote> > quote> pqr' > % arr=($(print -r -- $orig)) > % typeset -p arr > typeset -a arr=( abc def ghi jkl mno pqr ) It will take me a long time to understand that. > % cat foo.zsh > orig='abc > > def ghi > jkl mno > > pqr' > > # The sensible way to split on LFs. > #arr=("${(@f)orig}") > > # A very silly way to split on LFs. Use double quotes to > # prevent the result of $(...) from being split and to retain > # empty words in the result of ${(@)...}. > arr=("${(@f)$(print -r -- $orig)}") > > typeset -p arr > print -r -- $#arr > > # Use double-quoted $arr[@] to retain empty elements. Use > # "print -C1" to avoid printing an empty line if "arr" is empty. > print -rC1 -- "$arr[@]" > > % zsh ./foo.zsh > typeset -a arr=( abc '' 'def ghi' 'jkl mno' '' pqr ) > 6 > abc > > def ghi > jkl mno > > pqr > % I think I can chew on that, backatcha later. > You both populate and print your array incorrectly. For the umpteenth > time, you should use "typeset -p" to inspect your variables' values. > I keep typeset -p close at all times now.  But there are times when I'm still baffled.  Like an alchemist.  Sheesh, just yesterday I was attempting to transform this: typeset -g var=" abc     def ghi     jkl mno     pqr " ... into an array that retained the same 'shape' -- that prints verbatim -- and typeset -p showed newlines being transubstantiated into dollar signs!  God knows how. For now, what I'm wishing for is a nice, focused essay: "How to use '$#' to count whatever it is you want to count -- characters, words, lines, paragraphs (at one point my count was '3' which I'd approximate to being a paragraph) ... and all with or without spaces and/or empty lines. " Should run about  ten pages but it would be everything there is to know about '$#'. --------------nKhLZWIxpAjzpnKE8osdFfiC Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit

On 2024-04-11 21:55, Lawrence Velázquez wrote:

If eval really is necessary (to be frank, I don't trust your judgment
on this), show us examples that require it, instead of the misleading
Rube Goldberg machines you've been offering.
I don't trust it neither, and I taught Rube everything he knows.  Seriously, you won't sympathize, but the tinkerer's approach was the only one available to me at least until I had enough ad hoc code built up that sorta works to begin to start to try to understand it formally.  And my efforts to find patterns of behavior -- as you know better than anyone -- lead me to false conclusions all the time.  The manual is useless as pedagogy.  If there was 'zsh school' I'd enroll and learn my shell ABC's properly from the ground up.  But there isn't.  So I hack away.  But please understand I *hate* being me.  I like competence :( 
The count is correct by accident.  Your unquoted command substitution
drops the two empty lines but splits the two lines you say should not
be split.
Right, I'm aware of that possibility at least in theory.  Word splitting lurks.
	% orig='abc
	quote> 
	quote> def ghi
	quote> jkl mno
	quote> 
	quote> pqr'
	% arr=($(print -r -- $orig))
	% typeset -p arr
	typeset -a arr=( abc def ghi jkl mno pqr )
It will take me a long time to understand that.

	% cat foo.zsh
	orig='abc

	def ghi
	jkl mno

	pqr'

	# The sensible way to split on LFs.
	#arr=("${(@f)orig}")

	# A very silly way to split on LFs.  Use double quotes to
	# prevent the result of $(...) from being split and to retain
	# empty words in the result of ${(@)...}.
	arr=("${(@f)$(print -r -- $orig)}")

	typeset -p arr
	print -r -- $#arr

	# Use double-quoted $arr[@] to retain empty elements.  Use
	# "print -C1" to avoid printing an empty line if "arr" is empty.
	print -rC1 -- "$arr[@]"

	% zsh ./foo.zsh
	typeset -a arr=( abc '' 'def ghi' 'jkl mno' '' pqr )
	6
	abc

	def ghi
	jkl mno

	pqr
	%
I think I can chew on that, backatcha later.

You both populate and print your array incorrectly. For the umpteenth
time, you should use "typeset -p" to inspect your variables' values.

I keep typeset -p close at all times now.  But there are times when I'm still baffled.  Like an alchemist.  Sheesh, just yesterday I was attempting to transform this:

typeset -g var="
abc

    def ghi
    jkl mno

    pqr
"

... into an array that retained the same 'shape' -- that prints verbatim -- and typeset -p showed newlines being transubstantiated  into dollar signs!  God knows how. 

For now, what I'm wishing for is a nice, focused essay: "How to use '$#' to count whatever it is you want to count -- characters, words, lines, paragraphs (at one point my count was '3' which I'd approximate to being a paragraph) ... and all with or without spaces and/or empty lines. " Should run about  ten pages but it would be everything there is to know about '$#'.


--------------nKhLZWIxpAjzpnKE8osdFfiC--