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 CA3C526C07 for ; Tue, 5 Mar 2024 07:56:47 +0100 (CET) ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1709621807; b=VHtfF0VpegbHt2uc1Vf1IhicxRFNSayBrmPD6MYQsAhx2zjs8EtK3nLBFriZs6Ov1KC3DVWQbG yBnFgeurnfypSCsiRqbYxqsFpXPgwkIY+t6pOeERnyMVy92RfHPGhbGhpRn2sJtINj/vKaiXCJ NL5hILpskpEs4jgPBwl76aTdROcAJFtDe5+kFA7nHomGjswLtZG71jg9ML9MIlfS4zWPbtOBz4 a02JHbXbBFK8HlGSu6goagVPY5WkZDPSWZ4WdwZu+FLuapOGQMVZBiuDWViNc11JH/6zMWIte4 ZszzuZtEyqyJz9VInSCkWNXicInAL2N+7B95mSFr0pUK0Q==; 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=1709621807; bh=qEuWBmES66hecWmWTkQ1TBw0wphg4sL263qmpHGq5jU=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Content-Type:MIME-Version:References:Message-ID: Subject:Cc:To:From:Date:DKIM-Signature; b=jxrLwsJyrOppI04Te1BbmT2I9VrkC8yWuH58OnLcohvY+rRiwGdt4iwSh9MjRInZnSiMkupjZQ 3zYROtBtsKG8ory5g5NkUP4gOnjVYEeNgmzsGbzjDZksEJ83k80ILHd6c3qse9UJmMwdJBFU0g 5LXd1GEsfK41xrKKgirlxDrGyQSf2GvoiZQRBtaoHuswCsJ9qOjNCPDsBlp3OAChMBV97wezZx gQFDp4e8xr82+9V2hW5vYMHeiH6KRJapINgw4rGnj37AggwPKPwaJxcaM/lJhmc8EmjhJ1Hwht uOtdG6rllGMc1MEFx5AvvPLX/ucCY1bPRFxnkyx5MMu/HQ==; 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-Type:MIME-Version :References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=7lGFvG56Y6qycKGNyLUmCRvPx+WlMnN8uoZlNlixoPs=; b=iL9BkqQw6wzxXQ4OIgyEJpUKrX pJRB7wFvwg2u7e5IADmJb7ADKddILGBVqfVFnY6h98BOT8c5E4gZ0YYVSbP4mm5gfeqANXH+ZBqDh 9SD80s1Yy7KBad7lsATl/X6edyiLk1YRVBgC7bH0HnkhlJGTfykBtv4F9c5xx3tKxKSPqVBjgQb5u sQjf8FVyC1AdodQZVUyQo+iV1q0pWvycyyuhvNPKl9Y/VvJfOiri1X6cISgg1XH2w0s3+6T36cg+F mCpuuTsxM4/90CR/LO9Rtuabz2AhCQHbZ6iXL8ZjY0YpTFCaWrIHmRvtNIQd8P6nV7RVrOD5vMZds jBxdkHfg==; Received: by zero.zsh.org with local id 1rhOjG-000KRt-Ga; Tue, 05 Mar 2024 06:56:46 +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]:43379) by zero.zsh.org with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) id 1rhOie-000K7V-Qe; Tue, 05 Mar 2024 06:56:09 +0000 Received: by mail.gandi.net (Postfix) with ESMTPSA id EA57840002; Tue, 5 Mar 2024 06:56:07 +0000 (UTC) Date: Tue, 5 Mar 2024 06:56:06 +0000 From: Stephane Chazelas To: Bart Schaefer Cc: Zsh hackers list Subject: Re: [PATCH?] Nofork and removing newlines Message-ID: <20240305065606.ccr2ieheahslcpye@chazelas.org> Mail-Followup-To: Bart Schaefer , Zsh hackers list References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-GND-Sasl: stephane@chazelas.org X-Seq: 52682 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-04 21:52:02 -0800, Bart Schaefer: [...] > mytt($(command)) removes trailing newlines from the output of mytt(command) > - when substituting, whereas mytt(${ command }) and its variants do not. > - The latter is consistent with mytt(${|...}) from mksh but differs from > - bash and ksh, so in emulation modes, newlines are stripped from command > - output (not from tt(REPLY) assignments). > + when substituting, as does mytt(${ command }) when not quoted. Placing > + double quotes around mytt("${ command }"), or using either mytt(${|...}) > + format, retains newlines. The latter is consistent with mytt(${|...}) > + from mksh, but mytt("${ command }") differs from bash and ksh, so in > + emulation modes, newlines stripped even from quoted command output. ^^^ typo missing "are". To me ${ cmd; } being the non-forking version of $(...) should behave like $(...) in that regard. IMO, it's a bug in Bourne-like shells (and some others) that $(...) removes *all* trailing newline characters, but removing *one* is usually desired. As in: basename=$(basename -- "$file") should remove the newline added by basename, but not the newline characters that are found at the end of $file. In any case, I agree ${|cmd} should expand to the value of $REPLY as-is and trimming newlines there would not make sense. IIRC I already mentioned it here but maybe having a: ZSH_CMDSUBST_TRIM= (defaulting to $'\n##' for backward compatibility) could address the general issue with cmdsubst trimming too many newlines (for both $(...) and ${...;}). One would change it to ZSH_CMDSUBST_TRIM=$'\n' to get a saner default, or ZSH_CMDSUBST_TRIM= to not remove anything or ZSH_CMDSUBST_TRIM=$'(\r|)\n' or ZSH_CMDSUBST_TRIM='[[:space:]]##' to handle MSDOS line delimiters or remove any whitespace. > > When not enclosed in double quotes, the expansion of mytt($(command)) is > split on tt(IFS) into an array of words. unless called in non-list contexts such as in scalar variable assignment or [[ $var ]] or case $var in... See also: $ ./Src/zsh -c 'a=( "${(s[:])${ getconf PATH }}" ); typeset -p a' typeset -a a=( /bin $'/usr/bin\n' ) -- Stephane