This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: read -u how to


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@cs.nyu.edu
ZZZzz /,`.-'`'    -.  ;-;;,_		igor@watson.ibm.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
--
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/

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]