This is the mail archive of the cygwin@cygwin.com 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: Cygwin 1.3.10 read command and W2K


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/


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