delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/10/24/12:28:54

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Date: Mon, 24 Oct 2005 12:28:43 -0400 (EDT)
From: Igor Pechtchanski <pechtcha AT cs DOT nyu DOT edu>
Reply-To: cygwin AT cygwin DOT com
To: cygwin DOT 20 DOT maillinglist AT spamgourmet DOT com
cc: cygwin AT cygwin DOT com
Subject: Re: read -u how to
In-Reply-To: <F05AFBF84C348C4AAF1A0E7D126E370A249AC6@exbn01.DPEB.DE>
Message-ID: <Pine.GSO.4.63.0510241205450.27005@slinky.cs.nyu.edu>
References: <F05AFBF84C348C4AAF1A0E7D126E370A249AC6 AT exbn01 DOT DPEB DOT DE>
MIME-Version: 1.0

---559023410-959030623-1130171323=:27005
Content-Type: TEXT/PLAIN; charset=iso-8859-1
Content-Transfer-Encoding: 8BIT

On Mon, 24 Oct 2005, cygwin.20.maillinglist wrote:

> Hi folks
>
> I have the problem that I like to use read -u to read from file.
> The following script was stored under $HOME/bin/h
> ----------------------------------
> #!/bin/bash
> set -xv
> ls -l $HOME/bin/h
> 3<$HOME/bin/h
>
> while read -u 3
> do
>   echo $REPLY
> done
> ----------------------------------
> The output of a run is
>
> ----------------------------------
> ls -l $HOME/bin/h
>  3:  ls -l /cygdrive/c/home/bin/h
> -rwx------+ 1 F.Braunbeck Domänen-Benutzer 101 Oct 24 17:52 /cygdrive/c/home/bin/h
> 3<$HOME/bin/h
>
> while read -u 3
> do
>   echo $REPLY
> done
>  6:  read -u 3
> /cygdrive/c/home/bin/h: line 6: read: 3: invalid file descriptor: Bad file descriptor
> ---------------------------------
>
> How can I get it work so that no "Bad file descriptor" error comes out

Read the bash man page on input redirection.  This is not how you redirect
input in the current bash process.  Using

exec 3<"$HOME/bin/h"
while read -u 3; do echo $REPLY; done

works just fine for me.  Note that you may want to quote $HOME...
	Igor
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_		pechtcha AT cs DOT nyu DOT edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor AT watson DOT ibm DOT com
     |,4-  ) )-,_. ,\ (  `'-'		Igor Pechtchanski, Ph.D.
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

If there's any real truth it's that the entire multidimensional infinity
of the Universe is almost certainly being run by a bunch of maniacs. /DA

---559023410-959030623-1130171323=:27005
Content-Type: text/plain; charset=us-ascii

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/
---559023410-959030623-1130171323=:27005--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019