Problem when using variable assignment, backticks in shell script

Igor Peshansky pechtcha@cs.nyu.edu
Wed Aug 30 05:44:00 GMT 2006


Ugh, top-posting...  Reformatted.

On Tue, 29 Aug 2006, Tristen Hayfield wrote:

> Brian Dessent wrote:
> > "Silva, Russell" wrote:
> >
> > >   x=`/usr/bin/cat < temp`;
> >
> > I don't know what is causing your problem.  I ran your testcase several
> > times and never saw a failure, but from your description it seems like
> > it's the kind of thing that might occur very rarely.
> >
> > My only suggestion is that if your true desire is to actually read the
> > contents of a file into a variable, then the above construct is a fairly
> > expensive way of doing it.  This requires a fork/exec (an operation
> > which is extremely slow under cygwin) of /bin/cat, whose purpose is only
> > to read from one fd and write to another.  If you can live with a
> > bash-specific (?) construct, then x=$(< temp) should cause the same
> > effect but much more efficiently, as the shell itself just reads the
> > file without invoking any subprocesses.
> >
> > Brian
>
> One may also do:
> read x < temp
> in bash

Actually, it's more like

IFS='' read -rd '' x

but you have the general idea... :-)
	Igor
-- 
				http://cs.nyu.edu/~pechtcha/
      |\      _,,,---,,_	    pechtcha@cs.nyu.edu | igor@watson.ibm.com
ZZZzz /,`.-'`'    -.  ;-;;,_		Igor Peshansky, Ph.D. (name changed!)
     |,4-  ) )-,_. ,\ (  `'-'		old name: Igor Pechtchanski
    '---''(_/--'  `-'\_) fL	a.k.a JaguaR-R-R-r-r-r-.-.-.  Meow!

"Las! je suis sot... -Mais non, tu ne l'es pas, puisque tu t'en rends compte."
"But no -- you are no fool; you call yourself a fool, there's proof enough in
that!" -- Rostand, "Cyrano de Bergerac"

--
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/



More information about the Cygwin mailing list