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_EF,HEADER_FROM_DIFFERENT_DOMAINS,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 95DDC24AA6 for ; Wed, 6 Mar 2024 18:57:55 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1709747875; b=RvbuTlZc4a4vtGimpLtzTLEk8j76u9fzjFiRTjWWDU1uJWyGADtSoBwS5sw8baGwP0eFWtLfZE PUG6zHQouGClBTTXobR07xAfy0p7KU5h1KMgDDxJ4nqc49KnRFiP0xB+jlzQmBgK2eFrPCOZ+c 6O7Lp4hOLNXUON+p3krbA1B8guQ6B5LnRdaEKSy4eMh8o5YvTBupmPHjQlLQm9GQJU81oeiMEN EM88zRYes4f7zsc2wrAe3SwuheHdm3prGR1yXGQxGkPGf+5NKhwkZTygKLO/klUnacmfwxOfwD M9GiBksDDCEGdL7nkIDvqU/U74n7dY9xh/rfYKxucEvLLA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (relay2-d.mail.gandi.net) smtp.remote-ip=217.70.183.194; dmarc=none header.from=chazelas.org; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1709747875; bh=fnhYsP/2lwBDZFUJEdw84Qgb6nd4HE5jSwGzHpzEODU=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Transfer-Encoding:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:DKIM-Signature; b=jPgu4pqLO23nx/L15qaxMBezXMgMEBkGScIdXy9oLFRbmSytT4i/lh1q4VaAMpsZnm5npkCdk7 TONfVixCr6vgG1vASlJ8yTRDYyVJfMLfocSMDBiPMHagKlRSWjG7LbH43Gk6WExoBt/p+45rGw PJ9bKe4b47Jh3IsciuYnkpMbAMOKq7WulD48hMXMzNjwm0QCAFFecTU7Jj+qSyA+NPrr1sl8Ah I1OPFVz5Uih2m/E0JVhZ3L9/Xlsk/s7oMq0J/G7RcPaHN+a/qeTo5Sts7RkMb9Jv+vX2xjJRTL lWoilzmkM/JU+DOfPV0D2TgdXQZkhnEr4SGRln5XAqOlDg==; 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:Content-Transfer-Encoding :Content-Type:MIME-Version:References:Message-ID:Subject:Cc:To:From:Date: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID; bh=opyHI5gYyyF+HTzS/82UbDqcWwTAByB/CiU+Xlek4r8=; b=JxXXfHAxcx16LbyHzHbJpV9Xat 1EEIZWx9mNaSIGQgi+UPA5DqPN+v3yAoC5cKtPDqcmZ/CbfVbb66CvJI8EEH0mQJnogDpBY+wzQiR +cwVxPJlHtuUPOfzd9VHc8DPJJRXyolqLhvoZIUlz7e0G4/OsuBDAZ2V61YshUJod4CrQ2GUkCZay 9gX6YFQMsFSzkHTX/malghTpi8f4cNHuUEp0mby+pHYgyfH3BU2qoIYfoEDP6YAfyf5oBpXK2Njq4 YZi7yX8kBJJisc8bTqUVFKbsvmIlB3JZwLECa2sT2opZitmoS47hE+pl1FWYXlXydjB6K9n+1loGk 5tlex9bA==; Received: by zero.zsh.org with local id 1rhvWZ-000JaN-QT; Wed, 06 Mar 2024 17:57:51 +0000 Authentication-Results: zsh.org; iprev=pass (relay2-d.mail.gandi.net) smtp.remote-ip=217.70.183.194; dmarc=none header.from=chazelas.org; arc=none Received: from relay2-d.mail.gandi.net ([217.70.183.194]:50533) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1rhvVy-000JFh-8f; Wed, 06 Mar 2024 17:57:15 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id 2DF7F40008; Wed, 6 Mar 2024 17:57:12 +0000 (UTC) Date: Wed, 6 Mar 2024 17:57:11 +0000 From: Stephane Chazelas To: Bart Schaefer Cc: Zsh hackers list Subject: Re: [PATCH?] Nofork and removing newlines Message-ID: <20240306175711.t3uz2sery3b6tbjw@chazelas.org> Mail-Followup-To: Bart Schaefer , Zsh hackers list References: <20240305065606.ccr2ieheahslcpye@chazelas.org> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: X-GND-Sasl: stephane@chazelas.org X-Seq: 52693 Archived-At: X-Loop: zsh-workers@zsh.org Errors-To: zsh-workers-owner@zsh.org Precedence: list Precedence: bulk Sender: zsh-workers-request@zsh.org X-no-archive: yes List-Id: List-Help: , List-Subscribe: , List-Unsubscribe: , List-Post: List-Owner: List-Archive: 2024-03-05 14:48:00 -0800, Bart Schaefer: > On Mon, Mar 4, 2024 at 10:56 PM Stephane Chazelas wrote: > > > > To me ${ cmd; } being the non-forking version of $(...) should > > behave like $(...) in that regard. > > That's the starting point of this discussion, yes. > > > IMO, it's a bug in Bourne-like shells (and some others) that > > $(...) removes *all* trailing newline characters, but removing > > *one* is usually desired. > > Ignoring the many-vs.-one issue, the pivotal word here is "usually". > We can't change the behavior of $(...) but parameter expansions > already behave differently with respect to SH_WORD_SPLIT so we have > precedent for leeway on ${ ... }. The suggested change would provide > $(...)-like behavior for the usual case and a simple way to keep the > newline(s) in the less-usual cases. Sorry, I hadn't realised ${ cmd } also didn't do IFS-splitting, so it is indeed departing a lot from command substitution and assuming we don't care about keep compatibility with ksh93/mksh/bash, I agree the proposed behaviour makes sense and it's usefil to have a command substitution that doesn't trim all newlines, so as you say I can do for my previous example: basename="${${ basename -- "$file" }%$'\n'}" To properly get the basename of $file with basename. (yes, I know it's a bad example as we can also do basename=$file:t). > > IIRC I already mentioned it here but maybe having a: > > > > ZSH_CMDSUBST_TRIM= > > This is both IMO way too complicated and also misses the point that > newline trimming or not ought to be easily switchable in the context > of a single expansion, not globally. The idea would be to allow users to fix command substitution once and for all with ZSH_CMDSUBST_TRIM=$'\n'. So things like: basename=$(basename -- "$file") become correct regardless of the value of $file without to have to resort to ugly work arounds. set -o fixcmdsubstrnewlinetrimming would work as well be be less versatile. (I agree that in any case that's rather tangential to the question of what to do with ${ ... }) > My strong inclination is to either go with this patch or leave it as > is. The code change to implement this patch is literally two tokens. Either way or always removing all newlines or always removing one newline or removing one newline when not quoted are fine with me. -- Stephane