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 8A81D201BE for ; Thu, 11 Apr 2024 02:57:11 +0200 (CEST) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1712797031; b=OmtgP77+4C/ufDPCaAJAmbzeUgkedsa8YHOItUDzvlwgfNG3SPN/KHJCcATQ62mpssfZudXrAg nY1CzaryHRjACp514tOkU66BekCB8O2Rob7lAR3EALmkwt314DNJpxBs4Jn0Q+brR78UmSTpr5 QalU5ahe5SPT0idD1fYzCdre9gTNtFB9fKd1ik66CBbajOAX9yXF7c+3DCbs3EWqDOaHMEKs/A bVljvWxTHsQ3nLyDZzRI/mPFGELRONLRIBgcABoiEJdngGme4rvK2QQMchfS5iCRPXHad9EuoU CQQCRjb/8bDdCLLHtV2istZ9TIIEE4eYvE5dP1txiAeOzQ==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mta02.eastlink.ca) smtp.remote-ip=24.224.136.13; 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=1712797031; bh=qz6Sw9DhCdMVslRIBef4TkGS/n/Tfwp2IHC+F4RcPAk=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Subject:From:To:MIME-Version:Date:Message-ID:Content-Type: DKIM-Signature; b=B1derTspTl7k/I9mkWOBdxagCPVA1eeFGd2kqAIDI47q3a8wFQCyI50PiD9phff8+WR9bWjXmw p+HOws4fL5ihzWgvqTB8e90zhKCy4pfLi8yLunN2a8PyoXXh0ybmbePRstQAXujUn9orDyI4Uk vf4vxZgvn4pJqs5YoYu3nGdoGU8bQoh1erCLqVyK8ge5HIEKkAzg+Mok5wUjrKJ5LyxZ76/TUD qWJLZc6cV+XFeRieBGzzjT0w9nUpsXpCX1d2hDcFCG8DSoDdFba9q8jv/stjgO+qhIHU8JEHQp hPgNfFGzqrQ6SMg/rZQc/dNOKnEj8xSIB/Kx6wLTHkpJ+g==; 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:Subject:From:To: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:In-Reply-To:References; bh=mCskFIngNEyQg4kRi2mYweJOitduiGYapFBZZQdWBwg=; b=D+xUE9hu5eUMB0+6yMNss1swuJ xCJqVQC0TuF2FRn4kIS/j3K1qODlozOtMD1UC7LnP6KCboqJWKZq0NxLxqjXihPPBF5YwtGLp6Qdh OsGzz9tv0ftr+WzNinTblSVdtqZEH+lA/ZSRuk+3zIfpCqnRYTpImJZ/Aszi3WT3QU6/CKi91rZ+u K5YygJO/E4E7S+mQk5iSFBFcPSx+prl+JapdfsPTP/2/8ofmUkXa9vWdylCgwa/OdeMEZytUgR7At dU0ST5V9D0GCNbEQP4omDvztpVcGG8FG7LflOBQVY3BP7CostO8wmC4Gt+6IgV91zLSZOr8geGSmC 4H5GibNw==; Received: by zero.zsh.org with local id 1ruikY-000BSz-99; Thu, 11 Apr 2024 00:57:10 +0000 Authentication-Results: zsh.org; iprev=pass (mta02.eastlink.ca) smtp.remote-ip=24.224.136.13; dmarc=none header.from=eastlink.ca; arc=none Received: from mta02.eastlink.ca ([24.224.136.13]:59109) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1ruiju-000Aip-7A; Thu, 11 Apr 2024 00:56:33 +0000 Received: from csp02.eastlink.ca ([71.7.199.167]) by mta02.eastlink.ca ([24.224.136.13]) with ESMTPS id <0SBR294FD6M1GYU0@mta02.eastlink.ca> for zsh-users@zsh.org; Wed, 10 Apr 2024 21:56:29 -0300 (ADT) Received: from [192.168.0.11] (host-24-207-19-13.public.eastlink.ca [24.207.19.13]) by csp02.eastlink.ca ([71.7.199.167]) with ESMTPSA id uijsrR0945TsruijsrCV54 (version=TLSv1_2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256); Wed, 10 Apr 2024 21:56:29 -0300 X-Authority-Analysis: v=2.4 cv=deIj3mXe c=1 sm=1 tr=0 ts=6617353d a=e7T7DzMKK1R988ZCg0wLyw==:117 a=e7T7DzMKK1R988ZCg0wLyw==:17 a=r77TgQKjGQsHNAKrUKIA:9 a=_bTnUI_ciLK1wfb5jIYA:9 a=3ZKOabzyN94A:10 a=QEXdDO2ut3YA:10 a=UWJ7Qtj7W7kWT4tybRwA:9 a=yUpHxEO1yfmOzrpw:21 a=_W_S_7VecoQA:10 X-Vade-Cause: gggruggvucftvghtrhhoucdtuddrgedvledrudehjedggeduucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecugfetuffvnffkpffmpdfqfgfvnecuuegrihhlohhuthemuceftddtnecusecvtfgvtghiphhivghnthhsucdlqddutddtmdenucfjughrpegtkfffgggfvffhufesrgdtreertddvjeenucfhrhhomheptfgrhicutehnughrvgifshcuoehrrgihrghnughrvgifshesvggrshhtlhhinhhkrdgtrgeqnecuggftrfgrthhtvghrnhepfeefiedvtdekvdfgteekveduhfdtledtgeettddtkeeifffhuefhkeehgedtveetnecukfhppedvgedrvddtjedrudelrddufeenucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepihhnvghtpedvgedrvddtjedrudelrddufedphhgvlhhopegludelvddrudeikedrtddruddungdpmhgrihhlfhhrohhmpehrrgihrghnughrvgifshesvggrshhtlhhinhhkrdgtrgdpnhgspghrtghpthhtohepvddprhgtphhtthhopeerredprhgtphhtthhopeiishhhqdhushgvrhhsseiishhhrdhorhhgpdhgvghtqdgkihhprfgrshhsfigupehtrhhuvg X-Vade-Score: -100 X-Vade-State: 0 X-EL-AUTH: rayandrews@eastlink.ca Content-type: multipart/alternative; boundary="------------DP4RePD81meyVNAigMu0HQ4Y" Message-id: <97793422-1543-4ba6-b52b-ff93eba03ab1@eastlink.ca> Date: Wed, 10 Apr 2024 17:56:28 -0700 MIME-version: 1.0 User-Agent: Mozilla Thunderbird Content-language: en-US To: Zsh Users From: Ray Andrews Subject: triviality regarding $# counts X-Seq: 29793 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. --------------DP4RePD81meyVNAigMu0HQ4Y Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit This practice text is in a variable 'temp' and I want to count the number of lines inside a function that will also print the text exactly as shown, and do a bunch of other stuff. -------------------------------------------------------------------- xz-utils: /usr/bin/xzgrep /usr/share/man  /de/man1/xzgrep.1.gz    # Hafta be careful not to split here. /usr/share/man  /ko/man1/xzgrep.1.gz    # ... or here. /usr/share/man/man1/xzgrep.1.gz /usr/share/man/pt_BR/man1/xzgrep.1.gz /usr/share/man/ro/man1/xzgrep.1.gz /usr/share/man/uk/man1/xzgrep.1.gz /usr/bin/xzegrep /usr/bin/xzfgrep /usr/share/man/de/man1/lzegrep.1.gz /usr/share/man/de/man1/lzfgrep.1.gz /usr/share/man/uk/man1/xzegrep.1.gz /usr/share/man/uk/man1/xzfgrep.1.gz zsh-common: /usr/share/doc/zsh-common/examples/Functions/zpgrep /usr/share/zsh/functions/Completion/Debian/_grep-excuses /usr/share/zsh/functions/Completion/Unix/_grep /usr/share/zsh/functions/Completion/Unix/_ngrep /usr/share/zsh/functions/Completion/Unix/_pgrep zstd: /usr/bin/zstdgrep /usr/share/man/man1/zstdgrep.1.gz ----------------------------------------------------------------------------------- This works: (Again, this is deep in a function and I have to use eval.)     output=$( eval "$@" )   # '$@' will expand to 'print -l $temp' which is the text above.     temp=( $( eval $@ ) )    # To get the correct count I need to force an array.     linecount=$#temp     print -rl -- $output     print  $linecount Various experiments trying to get the correct linecount (23) *and* get it printing correctly all end up with waterboarding problems. If I do it in two stages as above, it's ok, but is seems very clumsy.  Different efforts at quoting or using ' ${(@f) ....} ' and various other tricks yield me a linecount of 1, 3, 23, 25, 26, or 738.  And output that deletes the blank lines, or forces everything into one 'line/element'.  Basically I need the array form to to get the line count, but it won't print properly as an array.  Not that it's worth much trouble, but is it possible to get the variable  to print correctly *and* show the count of lines without having to eval it twice?  schematically:     output=????$( eval ???)??? # Whatever the correct code might be.     linecount=$#output     print -rl -- $output     print  $linecount ... as it is, it seems that '$#' never counts the lines of output as it actually prints.  In practice it's hardly a problem but still it bothers me.  '$#' seems mostly to want to count characters (738). --------------DP4RePD81meyVNAigMu0HQ4Y Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: 8bit This practice text is in a variable 'temp' and I want to count the number of lines inside a function that will also print the text exactly as shown, and do a bunch of other stuff.

--------------------------------------------------------------------
xz-utils:
/usr/bin/xzgrep
/usr/share/man  /de/man1/xzgrep.1.gz    # Hafta be careful not to split here.
/usr/share/man  /ko/man1/xzgrep.1.gz    # ... or here.
/usr/share/man/man1/xzgrep.1.gz
/usr/share/man/pt_BR/man1/xzgrep.1.gz
/usr/share/man/ro/man1/xzgrep.1.gz
/usr/share/man/uk/man1/xzgrep.1.gz
/usr/bin/xzegrep
/usr/bin/xzfgrep
/usr/share/man/de/man1/lzegrep.1.gz
/usr/share/man/de/man1/lzfgrep.1.gz
/usr/share/man/uk/man1/xzegrep.1.gz
/usr/share/man/uk/man1/xzfgrep.1.gz

zsh-common:
/usr/share/doc/zsh-common/examples/Functions/zpgrep
/usr/share/zsh/functions/Completion/Debian/_grep-excuses
/usr/share/zsh/functions/Completion/Unix/_grep
/usr/share/zsh/functions/Completion/Unix/_ngrep
/usr/share/zsh/functions/Completion/Unix/_pgrep

zstd:
/usr/bin/zstdgrep
/usr/share/man/man1/zstdgrep.1.gz
-----------------------------------------------------------------------------------

This works: (Again, this is deep in a function and I have to use eval.)

    output=$( eval "$@" )   # '$@' will expand to 'print -l $temp' which is the text above.
    temp=( $( eval $@ ) )    # To get the correct count I need to force an array.
    linecount=$#temp
    print -rl -- $output
    print  $linecount

Various experiments trying to get the correct linecount (23) *and* get it printing correctly all end up with waterboarding problems.  If I do it in two stages as above, it's ok, but is seems very clumsy.  Different efforts at quoting or using ' ${(@f) ....} ' and various other tricks yield me a linecount of 1, 3, 23, 25, 26, or 738.  And output that deletes the blank lines, or forces everything into one 'line/element'.  Basically I need the array form to to get the line count, but it won't print properly as an array.  Not that it's worth much trouble, but is it possible to get the variable  to print correctly *and* show the count of lines without having to eval it twice?  schematically:

    output=????$( eval ???)??? # Whatever the correct code might be.
    linecount=$#output
    print -rl -- $output
    print  $linecount

... as it is, it seems that '$#' never counts the lines of output as it actually prints.  In practice it's hardly a problem but still it bothers me.  '$#' seems mostly to want to count characters (738). 



--------------DP4RePD81meyVNAigMu0HQ4Y--