From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 15558 invoked by alias); 1 Sep 2014 18:39:51 -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: 19047 Received: (qmail 28377 invoked from network); 1 Sep 2014 18:39:40 -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=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 From: Bart Schaefer Message-id: <140901113940.ZM2031@torch.brasslantern.com> Date: Mon, 01 Sep 2014 11:39:40 -0700 In-reply-to: <20140901075315.GA5908@localhost.localdomain> Comments: In reply to Han Pingtian "Re: cat as a builtin command" (Sep 1, 3:53pm) References: <20140901075315.GA5908@localhost.localdomain> X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: Han Pingtian , zsh-users@zsh.org Subject: Re: cat as a builtin command MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Sep 1, 3:53pm, Han Pingtian wrote: } } 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 I'm not able to reproduce this. Is this in a newly started shell? torch% (){ local fd function> exec {fd}<&0 function> read -E -u $fd function> exec {fd}<&- function> } hello hello torch% I *suspect* that what happened is that while you were experimenting, some previous "exec <&-" has already closed descriptor 0. Closing stdin is not fatal to an interactive zsh, it maintains its own descriptor for ZLE to access /dev/tty. E.g., if I explicitly do: torch% exec 0<&- Then up-history a couple of times and: torch% (){ local fd exec {fd}<&0 read -E -u $fd exec {fd}<&- } (anon):2: 0: bad file descriptor (anon):read:3: argument expected: -u (anon):4: failed to close file descriptor 0: bad file descriptor torch% What's puzzling to me is why line 4 says "0: bad file descriptor" rather than this: torch% exec {fd}<&- zsh: parameter fd does not contain a file descriptor It appears that only an UNSET parameter name triggers the "does not contain" error; a set-but-empty parameter is treated as 0 and closes standard input, which is likely how you got into this situation.