From: Peter Stephenson <p.stephenson@samsung.com>
To: zsh-users@zsh.org
Subject: Re: cat as a builtin command
Date: Fri, 29 Aug 2014 14:03:43 +0100 [thread overview]
Message-ID: <20140829140343.7ed2a891@pwslap01u.europe.root.pri> (raw)
In-Reply-To: <BLU436-SMTP2045383EF41756D3376DB3CF4DB0@phx.gbl>
On Fri, 29 Aug 2014 09:40:29 +0800
Izumi Natsuka <izumi.natsuka@hotmail.com> 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
next prev parent reply other threads:[~2014-08-29 13:03 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-08-29 1:40 Izumi Natsuka
2014-08-29 11:58 ` Roman Neuhauser
2014-08-29 12:24 ` Dirk Heinrichs
2014-08-29 13:20 ` Roman Neuhauser
2014-08-29 13:33 ` Dirk Heinrichs
2014-08-29 13:03 ` Peter Stephenson [this message]
2014-08-30 10:11 ` Mikael Magnusson
2014-09-01 7:53 ` Han Pingtian
2014-09-01 18:39 ` Bart Schaefer
2014-09-02 1:08 ` Han Pingtian
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20140829140343.7ed2a891@pwslap01u.europe.root.pri \
--to=p.stephenson@samsung.com \
--cc=zsh-users@zsh.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).