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.3 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED,UNPARSEABLE_RELAY autolearn=ham autolearn_force=no version=3.4.4 Received: (qmail 32739 invoked from network); 18 Jan 2021 03:11:01 -0000 Received: from zero.zsh.org (2a02:898:31:0:48:4558:7a:7368) by inbox.vuxu.org with ESMTPUTF8; 18 Jan 2021 03:11:01 -0000 ARC-Seal: i=1; cv=none; a=rsa-sha256; d=zsh.org; s=rsa-20200801; t=1610939461; b=EESpH22hAULIsSAIfqXWfBostsQtYowpMeWFS81tolw0kfHBr4JOiq7WLx0nSv7q9E4cAcpwh5 G2vTUvTyTUMEmTWnXh68blGkapgYusdFYDejrj0lxUY/ZR8/lU5bCojMfw0di0PrdOVvT3uQPp o8ZOoQ1vbvpqVs1WK579VjeNsU9sqAj/3pE7BN57GMNgOuen20InNf2BV/q44WRo4nCVpTLA7j 10HDn4q9/ntGM6vGNVd89E1zOaK/aV9q0r/PQkYPwDLyO5tXcIpPrX5aOWb4YVvdG7NHiFeJ1v 6RGJE6smWyPGNsq1N/+vn/No4OKhF94J/t6+Nafskt9ikA==; ARC-Authentication-Results: i=1; zsh.org; iprev=pass (mail-ot1-f49.google.com) smtp.remote-ip=209.85.210.49; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 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-20200801; t=1610939461; bh=G58cuYYY2aFwfdXZ+fvT45DiBkg0zwwEn10YAryOHGk=; h=List-Archive:List-Owner:List-Post:List-Unsubscribe:List-Subscribe:List-Help: List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID:Date:From:In-Reply-To: References:MIME-Version:DKIM-Signature:DKIM-Signature; b=qgpaoaOUGorNFY0/NfOHoiBWPuirM5EvXKHegIdQMty2gu0w+NkKJxFtqNDZ8bdQmNTaxL1uW8 I5cmB1riuw7alVAGIHYIy8znsN8xuRtxgMVeL+Dpwk9dd1v5pQHPe5ZUwHVGzhAiUC91W7pBRP HTGUakg0uEbHiLJCV0gWztSg5dw3+O6WAG/CsRIRA0BX1qPsoZWvirvdbOwTxXvSFFmbSuJVmn K1ZDbdiyR+kWWg8pWNFTCR1Fm1ZAfqJvKT6PqD3MxIsyzWFOalFKeqLtM1EN8honTNrAssUtqm eLsM5QcBhEeZ/cKmracnPgmS8d44nAnmG80hD09Vqvai4w==; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=zsh.org; s=rsa-20200801; h=List-Archive:List-Owner:List-Post:List-Unsubscribe: List-Subscribe:List-Help:List-Id:Sender:Content-Type:Cc:To:Subject:Message-ID :Date:From:In-Reply-To:References:MIME-Version:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID; bh=T5GxMs+1r1aP4B0NNOyYIhZO9hCARWnQ3GFpR764API=; b=grNtOvrIQifDPgP+Zgljxp53nz b+OHWWsdFdW9FA53Z4wrwY4w4ah2mfyiJdZUaj+/XTa0gXmOswn1sGNBiUP0rfgSInumsHUZK+C2u lMJAE5AL5o/to59dPYj2tMeuAE3ROwev7nHtPmVsbH4SxSuvHH+5EbUoCoLknP65jGnRpb6ZWyxKR dHDDsidgsy62FYafgIHwRrM9ro7GtuU/ie6DrLPhBBAuVeY/6zn9y+CBfoNpgPST1+gGsBUf4jEfm R96YONY+/Rw8CyOjjgGsBNcJWO/RN6ffwr1aUplfWdc3GMnfFxFyuOgzxqLso+fXd6quZ5qUV2LcE EbxKxOcg==; Received: from authenticated user by zero.zsh.org with local id 1l1KwV-000OWe-Kx; Mon, 18 Jan 2021 03:10:59 +0000 Authentication-Results: zsh.org; iprev=pass (mail-ot1-f49.google.com) smtp.remote-ip=209.85.210.49; dkim=pass header.d=brasslantern-com.20150623.gappssmtp.com header.s=20150623 header.a=rsa-sha256; dmarc=none header.from=brasslantern.com; arc=none Received: from mail-ot1-f49.google.com ([209.85.210.49]:40782) by zero.zsh.org with esmtps (TLS1.3:TLS_AES_128_GCM_SHA256:128) id 1l1Kvv-000O91-9e; Mon, 18 Jan 2021 03:10:24 +0000 Received: by mail-ot1-f49.google.com with SMTP id i20so7154899otl.7 for ; Sun, 17 Jan 2021 19:10:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brasslantern-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=T5GxMs+1r1aP4B0NNOyYIhZO9hCARWnQ3GFpR764API=; b=U+o51SCNh8xVreYI/r4zc6bXrMOeElvSjKu2xv+308m9mg9rfvHdqmi/ahFQNEzT8R hW2ak3cnzJXM4tyGWKhFdfY6j9swnXNHNlPiPEHE5whp2JP6ona7nbTVBLnO6ECZkOeA QKT+qEHYVTdHG6xnDdiIqT5lfNUdeImrNwSDSR4CO81PNaKywKC0aAlb6MHde+iJGY8p RlJAZzPzG7IUgwWbgMRDJyFg0mbh+Uz1v15SeUTswlsciKeaxZmILlf+dNzlShcUHRIr DoV9x/Dbl0BkqpXGAtMO2E5+FzD9w1h3zkPYz5V4DExdbbNOqyQhIxr7jY74rDuF+fQ/ O2NQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=T5GxMs+1r1aP4B0NNOyYIhZO9hCARWnQ3GFpR764API=; b=beL/HToD0TBKrYE2nZwqooFALyfeyPtfrF39U++bwemMfO0DATdcl7Hgp1TGB9GXdF pjkXA8FiAhOYDxu2Wc66GqP0gwMjNP4P2uFxopnDu22ekmNo2ARVT5vdxfrdJRpEq/Jl s9Di5XLFz8Q5i6AEzznW0p+b2R06rx5JdPd0Zf0bgxOESa0hyoyyk7Z304wWCN0w3fje VQOz3alxkc1PUeORLOyx5YYQae9AZ0q4Pax3jeftpTgC1APM4suUSUL4nqA+JvKPDmhr 5d1xjyrWtb8ty4XOi3xwNeVYJHLD0CwPvG629CZUwn4FQ8VzPUkSjL3HDxdSv+nZwnVG V1tQ== X-Gm-Message-State: AOAM533loDKCorVQLooX9VOHnvl0PukIqC8zPcoQLClrAEG27r4apuou PmslcBTdK+uUbPqtuw523nYHwpWCGp9cmZUObIkWQA== X-Google-Smtp-Source: ABdhPJz0+OB23JgeAEcuUovhR9HRMvBEGyUJQCXv3kc7KiV+kobRuhVGLTr6Pd8d3u7R4yow5a1FiodFJzq/EJTF1rM= X-Received: by 2002:a9d:470c:: with SMTP id a12mr16115339otf.161.1610939421641; Sun, 17 Jan 2021 19:10:21 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: From: Bart Schaefer Date: Sun, 17 Jan 2021 19:10:10 -0800 Message-ID: Subject: Re: xargs with zsh function To: Ray Andrews Cc: Zsh Users Content-Type: text/plain; charset="UTF-8" X-Seq: 26390 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: Archived-At: On Sun, Jan 17, 2021 at 3:12 PM Ray Andrews wrote: > > Can it be done? The problem isn't the pipe, it's that xargs isn't zsh. > How do we pipe into a function? That's the wrong question. You're not piping into a function, you're piping into a process (xargs) that turns its input lines into a set of command-line arguments. How about this: $ autoload zargs $ xzargs() { zargs -- "${(f)$(read -d '' -E)}" -- "$@" } $ ... | xzargs my_function That does use a lot of memory, reading the entire stdin and turning it into a command line. What you really want to do is write a nested shell loop that consumes N lines, then runs my_function, then does that again until it runs out of input; and pipe to that loop. There are a bunch of ways to do that. E.g.: ... | while (true) do set -- for i in {1..10} do read $i || break done my_function "$@" [[ $# -eq 10 ]] || break done