public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Re: Cygwin 1.3.10 read command and W2K
@ 2002-06-06 15:17 Gerald Reno
  0 siblings, 0 replies; 4+ messages in thread
From: Gerald Reno @ 2002-06-06 15:17 UTC (permalink / raw)
  To: cygwin

bash version is 2.05a.0(3)

--- Gerald Reno <grenoml@yahoo.com> wrote:
> I have scripts with reads that are failing.  Why
> doesn't "echo text | read var; echo $var" work?  var
> is just empty.  Doesn't 'read' default to stdin? 
> All
> other commands seem to be working only read is
> having
> problem.
> 
> 
> 
> __________________________________________________
> Do You Yahoo!?
> Yahoo! - Official partner of 2002 FIFA World Cup
> http://fifaworldcup.yahoo.com
> 


__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Cygwin 1.3.10 read command and W2K
  2002-06-07  1:09 ` Randall R Schulz
@ 2002-06-07  9:10   ` Gerald Reno
  0 siblings, 0 replies; 4+ messages in thread
From: Gerald Reno @ 2002-06-07  9:10 UTC (permalink / raw)
  To: Randall R Schulz, cygwin

Ah yes, I had forgotten about the subshell.  Isn't
there a construction such as "echo text |& read -p
var" that will allow you to read into parent shell?


--- Randall R Schulz <rrschulz@cris.com> wrote:
> Gerald,
> 
> [ The usual disclaimer: None of this is Cygwin
> specific. ]
> 
> 
> When you use a pipe, the shell forks. In your
> example, the read command was 
> occurring in a forked sub-shell, and hence the
> side-effect on $var is not 
> seen in the shell that reads and interprets the
> pipeline you gave (and 
> subsequent commands).
> 
> Compare the output of this pipeline:
> 
> % echo foo |read bar; echo $bar
> 
> %
> 
> With that of this one:
> 
> % echo foo | (read bar; echo $bar)
> foo
> %
> 
> 
> Depending on the complexity of your script, this
> construct might work:
> 
> % bar="$(echo foo)"
> % echo $bar
> foo
> 
> 
> Randall Schulz
> Mountain View, CA USA
> 
> 
> 
> At 13:01 2002-06-06, Gerald Reno wrote:
> >I have scripts with reads that are failing.  Why
> doesn't "echo text | read 
> >var; echo $var" work?  var is just empty.  Doesn't
> 'read' default to 
> >stdin?  All other commands seem to be working only
> read is having problem.
> 


__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Cygwin 1.3.10 read command and W2K
  2002-06-06 15:14 Gerald Reno
@ 2002-06-07  1:09 ` Randall R Schulz
  2002-06-07  9:10   ` Gerald Reno
  0 siblings, 1 reply; 4+ messages in thread
From: Randall R Schulz @ 2002-06-07  1:09 UTC (permalink / raw)
  To: Gerald Reno, cygwin

Gerald,

[ The usual disclaimer: None of this is Cygwin specific. ]


When you use a pipe, the shell forks. In your example, the read command was 
occurring in a forked sub-shell, and hence the side-effect on $var is not 
seen in the shell that reads and interprets the pipeline you gave (and 
subsequent commands).

Compare the output of this pipeline:

% echo foo |read bar; echo $bar

%

With that of this one:

% echo foo | (read bar; echo $bar)
foo
%


Depending on the complexity of your script, this construct might work:

% bar="$(echo foo)"
% echo $bar
foo


Randall Schulz
Mountain View, CA USA



At 13:01 2002-06-06, Gerald Reno wrote:
>I have scripts with reads that are failing.  Why doesn't "echo text | read 
>var; echo $var" work?  var is just empty.  Doesn't 'read' default to 
>stdin?  All other commands seem to be working only read is having problem.


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Cygwin 1.3.10 read command and W2K
@ 2002-06-06 15:14 Gerald Reno
  2002-06-07  1:09 ` Randall R Schulz
  0 siblings, 1 reply; 4+ messages in thread
From: Gerald Reno @ 2002-06-06 15:14 UTC (permalink / raw)
  To: cygwin

I have scripts with reads that are failing.  Why
doesn't "echo text | read var; echo $var" work?  var
is just empty.  Doesn't 'read' default to stdin?  All
other commands seem to be working only read is having
problem.



__________________________________________________
Do You Yahoo!?
Yahoo! - Official partner of 2002 FIFA World Cup
http://fifaworldcup.yahoo.com

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Bug reporting:         http://cygwin.com/bugs.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2002-06-07 15:31 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2002-06-06 15:17 Cygwin 1.3.10 read command and W2K Gerald Reno
  -- strict thread matches above, loose matches on Subject: below --
2002-06-06 15:14 Gerald Reno
2002-06-07  1:09 ` Randall R Schulz
2002-06-07  9:10   ` Gerald Reno

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 read-only IMAP folder(s) and NNTP newsgroup(s).