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,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 249C7222F1 for ; Sat, 13 Apr 2024 22:54:17 +0200 (CEST) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1713041657; b=CPGprjMeSL6ns0WKVN1cng/0mP+p4wCW8JQKYamf4VL2UELrm3z13sLZHxa9VRaFEJeBqaWWaF oQiHT20wyxWDs/aVTy50HIRWwZr8SZBU4qvkj6fV/47hZcmCcrrkkh2kGNJKYBMHrHOhuijStS DWKOnlD9a1qBKsk57QETn+FP+txTektAVkyalKvfKj2qpuD7m0neJ7Vg9/VODcsbMZp/cMYc/s Lbf54LSqPfz2AxLYFxn1LDM+wEYJR37ADqG2R36Ojjq8KEdB5CVFDVLB8vQr8or2CwCpRKaDGA w4tGERJF/FWM59SdAoMNLd3kbc5Dvzf2Aam1Xa/4DNm3Fw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-lf1-f53.google.com) smtp.remote-ip=209.85.167.53; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 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=1713041657; bh=uG2FcuhAXPMUr292vKDv7pEB9abKb+B5Tdf8eT4b9f4=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Transfer-Encoding:Content-Type:To:Subject:Message-ID: Date:From:In-Reply-To:References:MIME-Version:DKIM-Signature:DKIM-Signature; b=RxrbTrJTKYJe7sv3+gG18QcpW0lqvkjxp+BiGYMH9L3sj3pA/1O/2yhRIceSLDJfH3LdZWTeEz HVdWovqemrOSSnYIfljva5kZu6gHebvIzjZIqCTWU+QvFCUuG2zukcj90DCnPENFidgHxVcO+G Uhl60dOkyxggj2knYb/rU7l4cwg8Po1RjYwANC23+WVxhhyM+oNy1I8rivcsQBICbVQ79dAx2O Z9M54IP2243n4j+sJbNtoSCc6zokD2NjYg67/3jrsA3x8S0VsGks/C3MplInCenR4/xQ7IkE/y 2V9UIRqnxzHWrzK1nrQc2/GM1QxkKty6+3QRCnzVSRwgeQ==; 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-Transfer-Encoding: Content-Type:To:Subject:Message-ID:Date:From:In-Reply-To:References: MIME-Version:Reply-To:Cc:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=kI17xJyvmPLPs1oxXmldREuR5T2FuPIpZjpMjowF4uA=; b=jU6YFkMCiV0SWO+aeoz6BdxFGQ s+QIdEG9YY4i3cmutqnwFAOl9a9eCh5ss3MuKijTjf/eS5/+FaEiLdsZmFVWe9zMuNDFOrexjPAMa OKbOfefZxLxLrPVTR2i9xiqzzcuXmCVTZRkGiYM76l8viLSeUYma6Qs5P9O52XNOrrwF/ksiClLBW T4CKwAkF0vOEGHKQYKlr5VvOyGegOQfqfj8zws6ZOQVJRY7mVBr+WcanJV43PQAiUQL0vsnotRWR6 prazutnpdkKmsA1d+Ro44pFqF4PahTjTFEWoQzBpuUe0F9wSm2NwZi7CBIXhovg94oWuR9clxt6Eo cRTCLsuA==; Received: by zero.zsh.org with local id 1rvkO9-0002nX-CY; Sat, 13 Apr 2024 20:54:17 +0000 Authentication-Results: zsh.org; iprev=pass (mail-lf1-f53.google.com) smtp.remote-ip=209.85.167.53; dkim=pass header.d=brasslantern-com.20230601.gappssmtp.com header.s=20230601 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-lf1-f53.google.com ([209.85.167.53]:52267) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1rvkNZ-00028x-IC; Sat, 13 Apr 2024 20:53:43 +0000 Received: by mail-lf1-f53.google.com with SMTP id 2adb3069b0e04-5176f217b7bso3506170e87.0 for ; Sat, 13 Apr 2024 13:53:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20230601.gappssmtp.com; s=20230601; t=1713041621; x=1713646421; darn=zsh.org; h=content-transfer-encoding:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=kI17xJyvmPLPs1oxXmldREuR5T2FuPIpZjpMjowF4uA=; b=Vs/5mgsqYJgBwPi/NvSmrREzuduj6xW8sMkvm/oIQy5EI5wBZipVkj0nMnorYbD1Zh sFuuLqeLFruJDHbU1kUuAehPKjkHxSBhynlOqHu/pVThA99ab/DnHrUyO6OcWqieZVA+ U574pzIRqE1uP2CX1LIpU/eNVphLVHJVxLc8k9dwIYZAWZqkX930LPgU5XR02JhCr+8z LrE9e96SwhMkkfAZ1tgBbzA7r+qq/efNlIYXnh0SBUHh2ev4ABSFQpfaYIoY2j9OfDzS wS1FWx7yQOy6qi4VGxUpSsdM2KKmBAWH0pIKa5g6Y5s4h7qrCURjfPtd9KuHRF9TJ6Fl gs4A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1713041621; x=1713646421; h=content-transfer-encoding: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=kI17xJyvmPLPs1oxXmldREuR5T2FuPIpZjpMjowF4uA=; b=XHB6uK30smpp25OTIzr2QzgkxcXmhcfJ3SNpxfqqcTEcJFABXcrfLcCqaHA3TwQIfg GF1Yi1DCxWL5AnYsYd6+TIb+caNjn95nQ1e4oAx5JGOvas1/i4ugmJQ8NW1a5mJbTAgv Uw0MRa/GZQkyUUvSDW/r7/esiRPxEdA4svirLnTn43i2zJnLNmSc8TOpQRu84MykTL6n kgNMofGGbLMprPE0SUz8tIr+DU/0h0/NviEhBdK3gyyKjhQbj7Iiv8YiYrZRSDUfjiH2 8+6ln+fwwuGXhTsU3aPUnAhkXznIfRPqlnq2Xw/IkZFXlzXpedq2e3rdyya7o0kOdlnp 7iPg== X-Gm-Message-State: AOJu0YwVx315BeWdtcvjGPlgRLIfhPtkdzF0hHOCaF5t070JRnayDfsq 6v9QMnDa2FQIrUJg13GeFZ6ehQ/aZF1NBKW1ROdnBN40BMx5k+MvmIabow5lUU/9KWEKtOvI5lF kI0mH0xOXw1AddwCZIlZ30cQaCGft2RHSojnnIDRWIh8+nC9FZNlq X-Google-Smtp-Source: AGHT+IGxCQT7OW5oH4R7vh24mGro7fcj1LkAIqTHMWmR08RFC1x+YwYMiJ3d8VeAG99M7vtMEJrVyGJ30jQBDrvf5SQ= X-Received: by 2002:a05:6512:2247:b0:515:d176:dfd1 with SMTP id i7-20020a056512224700b00515d176dfd1mr5779109lfu.56.1713041620691; Sat, 13 Apr 2024 13:53:40 -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> In-Reply-To: From: Bart Schaefer Date: Sat, 13 Apr 2024 13:53:29 -0700 Message-ID: Subject: Re: triviality regarding $# counts To: zsh-users@zsh.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Seq: 29810 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 Sat, Apr 13, 2024 at 8:14=E2=80=AFAM Ray Andrews wrote: > > Anyway, it comes clear: '${(@f)....}' doesn't ADD (or retain) newlines it= removes them! (Tho splitting the array where they used to be.) Doesn't ne= ed them cuz elements aren't separated by newlines (like I thought) but by .= .. however it's done. (Liberties taken with historical accuracy below, do not feel compelled to leap in with sequencing corrections, etc.) In the beginning, there were only environment strings ($SHELL, $PATH, etc.) and positional parameters ($1, $2, etc.). When a command was run, it got its arguments as an "array" of positional parameters. This is how "variables" came to be called "parameters" in shell jargon. This mapped directly onto C main() argc ($#) and argv[] ($@) with the phantom $0 as the name of the command. Referencing an environment string or an individual positional parameter without quoting in a command argument caused the value to be split on whitespace (as defined by the value of $IFS) to convert it into an argv array. Putting it in double quotes protected it from that splitting but still permitted it to be replaced by its value. Single quotes were for literal strings. To reference an entire argv without further splitting but also without losing its array property, "$@" got the special meaning to quote each element individually. $* would give the entire argv but also split it further on whitespace, and "$*" gave the entire argv joined back together with with spaces to make it a single string. It follows from this that it's useful to be able to assign names to strings other than environment strings and to arrays other than the positional parameters. Thus we get scalar parameters and array parameters, but they still follow the rules corresponding to environment strings and positional parameters including the $* and $@ references to the full arrays, except now the name is added as in ${ary[3]} and ${ary[*]} and ${ary[@]}. From this point forward shells began to vary on details like whether named arrays begin with index 0 or 1 and whether it was necessary to wrap the reference in braces and (in zsh's case) whether splitting on whitespace happens by default. The salient point here is that regardless of the internal representation of an array, you can think of it like an argv[] in C. The elements are separated by conceptually being different string pointers, and anything you "see" from e.g. "typeset -p" is language syntax, not representation. When you use (f) and other syntax to split something, you're creating (temporarily) that same kind of array. It might collapse to a string again almost immediately based on context, which is why you might need e.g. (@f) to specifically preserve it, but it exists however briefly in that form. > Single quotes indicate elements. Thus, that's an effect of "typeset -p" rather than anything about the internal representation.