From: Han Pingtian <hanpt@linux.vnet.ibm.com>
To: zsh-users@zsh.org
Subject: Re: cat as a builtin command
Date: Mon, 1 Sep 2014 15:53:15 +0800 [thread overview]
Message-ID: <20140901075315.GA5908@localhost.localdomain> (raw)
In-Reply-To: <BLU436-SMTP2045383EF41756D3376DB3CF4DB0@phx.gbl>
On Fri, Aug 29, 2014 at 09:40:29AM +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:
>
> cat() {
> if [[ $# -le 1 ]] && [[ ${1:0:1} != '-' || ${1} == '-' ]];then
> local file
> exec {file}<${1:-0}
If there is no argument to cat, this line would be
exec {file}<0
It should be
exec {file}<&0
right? But I get error mesage for it:
localhost% (){
function> local fd
function> exec {fd}<&0
function> read -E -u $fd
function> exec {fd}<&-
function> }
(anon):2: 0: bad file descriptor
(anon):read:3: argument expected: -u
(anon):4: failed to close file descriptor 0: bad file descriptor
0 isn't a good descriptor here?
next prev parent reply other threads:[~2014-09-01 8: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
2014-08-30 10:11 ` Mikael Magnusson
2014-09-01 7:53 ` Han Pingtian [this message]
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=20140901075315.GA5908@localhost.localdomain \
--to=hanpt@linux.vnet.ibm.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).