Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: cat as a builtin command
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author