Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: cat as a builtin command
- X-seq: zsh-users 19045
- From: Mikael Magnusson <mikachu@xxxxxxxxx>
- To: Zsh Users <zsh-users@xxxxxxx>
- Subject: Re: cat as a builtin command
- Date: Sat, 30 Aug 2014 12:11:46 +0200
- 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==
- In-reply-to: <20140829140343.7ed2a891@pwslap01u.europe.root.pri>
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
- References: <BLU436-SMTP2045383EF41756D3376DB3CF4DB0@phx.gbl> <20140829140343.7ed2a891@pwslap01u.europe.root.pri>
On 29 August 2014 15:03, Peter Stephenson <p.stephenson@xxxxxxxxxxx> wrote:
> On Fri, 29 Aug 2014 09:40:29 +0800
> Izumi Natsuka <izumi.natsuka@xxxxxxxxxxx> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author