From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23946 invoked by alias); 30 Aug 2014 10:12:03 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 19045 Received: (qmail 21661 invoked from network); 30 Aug 2014 10:11:51 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=0+8VDCw7JuiTP+/a3K7CXIPvTrMFzgxPUd82Ec8SVw8=; b=tRL0QDd4bUj60ASYAoZEeqgy1byDHs7XvBUXc/HR6OtUxFUIFZEl4cNCFTRDPT7KHq EzUanBwTvmxaZN42wavfxX8U8uPVblELZ3K7UNkide8tm1N3K8J9cxsRsjkZW8Jo5Kps 1XOBtQQ0wx3yLOeEqwYq3I8lXXBhF2QzxanOr7ps6DJ3pegNMO0MPN01Ha/rrEnHRbmA 459+kKTxTWZ3DYo2u4RyoNaTHVuSoODTJ2oFnyzM2fAhhyK+KDJHeRbn1KJOF6oefjcb 6+o4i0DxMatgP3WNYgSCpSUs9UYTtiGWAMsxHma0MV1gsrHMHrSJxENEyMqPQz2S+pBb BOTg== MIME-Version: 1.0 X-Received: by 10.224.62.8 with SMTP id v8mr26072671qah.9.1409393507000; Sat, 30 Aug 2014 03:11:47 -0700 (PDT) In-Reply-To: <20140829140343.7ed2a891@pwslap01u.europe.root.pri> References: <20140829140343.7ed2a891@pwslap01u.europe.root.pri> Date: Sat, 30 Aug 2014 12:11:46 +0200 Message-ID: Subject: Re: cat as a builtin command From: Mikael Magnusson To: Zsh Users Content-Type: text/plain; charset=UTF-8 On 29 August 2014 15:03, Peter Stephenson wrote: > On Fri, 29 Aug 2014 09:40:29 +0800 > Izumi Natsuka wrote: >> Hello, I'm going to write a shell function that provides a basic >> functionality(print the content of a file or stdin) of cat[0], in >> order to avoid forking too many process when I call it in a >> loop[1]. And I have put the following in my zshrc: > > If it's just printing the contents of a file, investigate zsh/mapfile. > This turns off multibyte mode to make it easier to do binary files --- > there should be no disadvantage here as you just want a byte stream. > > > mycat() { > emulate -L zsh > unsetopt multibyte > zmodload zsh/mapfile > print -r $mapfile[$1] > } > > > This only works for files in the file system, not file descriptors, > pipes etc. For those you can often optimise out the cat entirely. > > pws mycat() { for i { print -r - "$(< $i)" } } (also only works for files) -- Mikael Magnusson