From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 17250 invoked from network); 24 Oct 2021 00:57:04 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 24 Oct 2021 00:57:04 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20210803; t=1635037024; b=ccK110EIVQLFyyBIQhPemuFZEAp33th0lFm4D3AaUW883IcS9dwI/qT/3gOpEYeDGgCTyzV+kM BLwA9/fbpKg7Ruo/MHkz/ABQncxI84xvNQmsCnMDFJJLhRAthG06mbO5ySqgF+5jpX5/bR+AMM c7FkPutogugPw24qJyoR/zTico0NOmXicqHfhrCaqHrdHs8l2dYffMrS+MMWFrKnMhIygPMsab k9oQ7H07vNKgiQKhYBF3tctZgFxxAWyDPQC22/wdv/o2MMASWUtZMlhv+JZxk0w48WZh+T6vvh R0EDcH3X42CM6BoVl27tVteJKfIGpTGTh81uMSedpT8wlw==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (smtp.vivaldi.net) smtp.remote-ip=31.209.137.12; dkim=pass header.d=vivaldi.net header.s=default header.a=rsa-sha256; dkim=pass header.d=vivaldi.net header.s=default header.a=rsa-sha256; dmarc=pass header.from=vivaldi.net; arc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed; d=zsh.org; s=rsa-20210803; t=1635037024; bh=GyfOXpLzZys7FZcGFAsWSxQQ74v4IbJVr218tFnfx54=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:In-Reply-To:Message-ID:Date:From:Subject:Cc:To:Content-Type: DKIM-Signature:Content-Transfer-Encoding:DKIM-Signature:DKIM-Signature; b=Ueij/aR4nNEwLhn9tDECHvWIaMO6e8w9C1F4hZWqRzWFv6dQpqM6sd6Iu8/KqhK3EWGrdJBsFN HzWfs4JeXjNPAbRYvKn/V9FobyG5lYkveH1LTj4Av+4vvWJa9n1Z/BV9ZY40EluXN5YYdTKXQZ SgGc4EBu6vS4Jzq93oodo2yOqIkS6s8eChiIMwffVsAP2jnT8UXjj1uiu+TRcV1XcN46mxOceX wILZr/oV+X9gGXkQ+ol/OC95R75+IEUA2IkhOBQBRDtVi23MA5vQkm4Xcm4uGPM4IFQNkwwgAw SrIXeCu9EbYqcEOeMACDLbvPYFjf8LZx9mNZO7KZdXid7Q==; 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:Message-Id:Date:From: Subject:Cc:To:Content-Type:Content-Transfer-Encoding:Reply-To:MIME-Version: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:References; bh=FtEI6F05Ti3t+YWHTRq8P6Cz66ZTFi2u6VEfrelXkos=; b=NUFrisReGbCPDulGfv/mifyrSW wtCU6t+R6KjkHx26R7rnvdj700KK3l6YKqExapU8uULSux2nPVB9elxrsefrDAQXlP8K2ywZXY+92 L/2utazSOf2CMm7oMI2UD9CE7KwSVGRG8G/oj/V7wSr8NIeWz8ztbaLQ4yDMfSWpY0MGIfy5L75tg euBDKAMZJ0I4ILh/HvQRBRIvOvJZXdJKJMQ30qbzVAx0v/uUxwBjjGUfTwjIPaIpMOeU2VPVuhHW0 4SZyDkOXxVaPQPXOr1RZ0Nif53Wr4nuzJjg7yUliHUQSJm22O9xGHAM/JeoH414+PHVnQJXmG8xnn jfUxAwjA==; Received: from authenticated user by zero.zsh.org with local id 1meRou-0005LI-55; Sun, 24 Oct 2021 00:57:04 +0000 Authentication-Results: zsh.org; iprev=pass (smtp.vivaldi.net) smtp.remote-ip=31.209.137.12; dkim=pass header.d=vivaldi.net header.s=default header.a=rsa-sha256; dkim=pass header.d=vivaldi.net header.s=default header.a=rsa-sha256; dmarc=pass header.from=vivaldi.net; arc=none Received: from smtp.vivaldi.net ([31.209.137.12]:48784) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_256_GCM_SHA384:256) id 1meRoB-0004ad-SR; Sun, 24 Oct 2021 00:56:21 +0000 Received: from localhost (localhost [127.0.0.1]) by smtp.vivaldi.net (Postfix) with ESMTP id 436D9BD05F; Sun, 24 Oct 2021 00:56:19 +0000 (UTC) DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.vivaldi.net 436D9BD05F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivaldi.net; s=default; t=1635036979; bh=FtEI6F05Ti3t+YWHTRq8P6Cz66ZTFi2u6VEfrelXkos=; h=To:Cc:Subject:From:Date:In-Reply-To:From; b=jDjCyB0Zk1d8ADn9M/uZ7Ce5FcS+T71rTMEP5hRqUAbiYaV5PF3MJY3o6noKimzQ9 NRRwTEQjJLPhx8GW5gXzzR/dFLvpvytCf+dA47L0wha51X/nbs1JZle8VAr1eGgh0A OvBDCs+/wt+URu42dwRl4b3lZGj1FFDGfxmFI1mTYCTEU6f81K+uQ00gVuS5SZRIYI JblVk/d5ofrnPli5+JuEpJW//B28aH4EKxAamv1NzNZyoqqTUIdIg0R5bEogVNwtaX d6+ZG4sdviwNAe8IH/TFtAKBFTkcH/RAtUZAnTTbnR0w9iPo3z/8bTVh8FSKdoGTul Q3Vc6SJQtZ/KA== X-Virus-Scanned: Debian amavisd-new at smtp.vivaldi.net Received: from smtp.vivaldi.net ([127.0.0.1]) by localhost (mxo.viv.dc01 [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id O1HRbeaUCTDa; Sun, 24 Oct 2021 00:56:15 +0000 (UTC) Content-Transfer-Encoding: quoted-printable DKIM-Filter: OpenDKIM Filter v2.11.0 smtp.vivaldi.net 3D4E4BD06B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=vivaldi.net; s=default; t=1635036975; bh=FtEI6F05Ti3t+YWHTRq8P6Cz66ZTFi2u6VEfrelXkos=; h=To:Cc:Subject:From:Date:In-Reply-To:From; b=Xl6a+ST1dwe19ideX2764JjeqglXULfj2mAeVUoeG37DCcDqwkMOzbDPwPhfIUVju 4VvBMuA3Pj6tQJY+uc9/NQFStG4PRS8/9dsGzxvFOnbpuBcK/BG/HxnWg7ZpZRlR9I 8lY5OHHcksSQnjmQ4aKWgwpHZpVrE8ht0oWlGiS4+XM+cD5m8dzhsAVnBkFa+G1HfL ZgBdYQCbfxpnNFkS87kzQCOjEUscfbzpwWtW+LHvBofYhDJRYEpWFvFaXLyCThRW2z wgOvvxgMrOWWB7deWXG72brUin3PFk3YwwJK7fSBbkQwnKxRrKl2booySDj51NilPz 3Rgx5wd/6gZew== Content-Type: text/plain; charset=UTF-8 To: "Pier Paolo Grassi" , "Bart Schaefer" Cc: "Vin Shelton" , "Peter Stephenson" , "Zsh-Users List" Subject: Re: Most Recent File From: "Paul" Date: Sat, 23 Oct 2021 19:32:09 -0500 Message-Id: In-Reply-To: X-Seq: 27280 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: Fundamentally, you're dealing with a limitation of Zsh (and almost all other shells): There is no way to "return" a list from a function. $( ) captures stdout, which is a *stream*, not inherently a list or any other structure. Using $( ) means you have to serialize your data, even if only by putting NULs between each element: recent(){ local l=3D( *(om[1,$1]) ) print -rn ${(pj:\0:)l} } ls -ld -- "${(0)$(recent 3)}" There's an alternate convention in shell programming where results are instead saved in a parameter, either of the user's choosing, or sometimes hardcoded as 'reply'. recent(){ # Use $reply if no parameter name given typeset -ga "${2:=3Dreply}" set -A "$2" *(om[1,$1]) } recent 3 files; ls -ld $files This way, there's no serialization, forking, or reading and writing to pipes. On Sat Oct 23, 2021 at 7:24 PM CDT, Pier Paolo Grassi wrote: > >That doesn't work because if one of the file names has a newline in > >it, (f) will split it into two words. (Also I think you left out an > >open paren.) > > sorry about that, I haven't ever considered newlines in filenames, since > I > wouldn't put them in the first place. Of course that's not to say that > cannot happen anyway, of course. > And yes, it should have been: > > ls "${(f)$(recent 3)}" > > thanks for catching that > > Pier Paolo Grassi > > > Il giorno dom 24 ott 2021 alle ore 00:42 Bart Schaefer < > schaefer@brasslantern.com> ha scritto: > > > On Sat, Oct 23, 2021 at 1:57 PM Pier Paolo Grassi > > wrote: > > > > > > and use it like this: > > > > > > ls "${(f)$recent 3)}" > > > > That doesn't work because if one of the file names has a newline in > > it, (f) will split it into two words. (Also I think you left out an > > open paren.) > > > > print -lr -- ${(q)f} > > > > and then > > > > eval ls -ld $(recent 3) > > > > seems to be the closest thing. > > > > > Il giorno sab 23 ott 2021 alle ore 22:44 Vin Shelton < > > acs@alumni.princeton.edu> ha scritto: > > >> > > >> What am I doing wrong? Does quoting not work correctly in captured > > output? > > > > The trouble is that "ls" doesn't interpret the quoting, when $(...) > > preserves it. So you have to emit the quotes in a form that the shell > > can interpret, and then use "eval" to make that happen. > > > > For extra safety, you could use ${(qqqq)f} instead. > >