From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 24819 invoked by alias); 29 Aug 2014 13:03:52 -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: 19042 Received: (qmail 3411 invoked from network); 29 Aug 2014 13:03:50 -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=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI, SPF_HELO_PASS autolearn=ham version=3.3.2 X-AuditID: cbfec7f5-b7f776d000003e54-8a-54007a31a57b Date: Fri, 29 Aug 2014 14:03:43 +0100 From: Peter Stephenson To: zsh-users@zsh.org Subject: Re: cat as a builtin command Message-id: <20140829140343.7ed2a891@pwslap01u.europe.root.pri> In-reply-to: References: Organization: Samsung Cambridge Solution Centre X-Mailer: Claws Mail 3.7.9 (GTK+ 2.22.0; i386-redhat-linux-gnu) MIME-version: 1.0 Content-type: text/plain; charset=US-ASCII Content-transfer-encoding: 7bit X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFuplluLIzCtJLcpLzFFi42I5/e/4FV3DKoYQg2cXuC12nFzJ6MDoserg B6YAxigum5TUnMyy1CJ9uwSujFffNzMWrGar2HhhCUsD42+WLkZODgkBE4mH59axQ9hiEhfu rWfrYuTiEBJYyigx/3QnK5TDJHHu/T2wKhYBVYlXs98wg9hsAoYSUzfNZgSxRQREJZav2AxW IwxUM3t5LyuIzStgLzH/8guwek4BO4nlPfPYQGwhAVuJnz3XwGx+AX2Jq38/MUFcYS8x88oZ RoheQYkfk++BXcosoCWxeVsTK4QtL7F5zVvmCYwCs5CUzUJSNgtJ2QJG5lWMoqmlyQXFSem5 RnrFibnFpXnpesn5uZsYIUH4dQfj0mNWhxgFOBiVeHhfZDCECLEmlhVX5h5ilOBgVhLhfZsI FOJNSaysSi3Kjy8qzUktPsTIxMEp1cB4sLXy4cVFV3jSLZbGsixXX6OQ+6w+e0PJi10ic8yr k0L3pLHOLv3IoHAjJnOh+533Uk4v/2hF7nyuVLZKyeWqwMw9PO9/p83fy175cEJErZb0Cwvh 2VM9BTL+Gu78ILUx1PXJX7XE/l3r1lRM4zomzJA4xyvnnc+umvN2J1Vit676NFu+uXmKEktx RqKhFnNRcSIAZAuLcyACAAA= 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