public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Randall R Schulz <rrschulz@cris.com>
To: Gerald Reno <grenoml@yahoo.com>, cygwin@cygwin.com
Subject: Re: Cygwin 1.3.10 read command and W2K
Date: Fri, 07 Jun 2002 01:09:00 -0000	[thread overview]
Message-ID: <5.1.0.14.2.20020606224316.01bfadc8@pop3.cris.com> (raw)
In-Reply-To: <20020606200157.84987.qmail@web14405.mail.yahoo.com>

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/

  reply	other threads:[~2002-06-07  5:52 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-06-06 15:14 Gerald Reno
2002-06-07  1:09 ` Randall R Schulz [this message]
2002-06-07  9:10   ` Gerald Reno
2002-06-06 15:17 Gerald Reno

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5.1.0.14.2.20020606224316.01bfadc8@pop3.cris.com \
    --to=rrschulz@cris.com \
    --cc=cygwin@cygwin.com \
    --cc=grenoml@yahoo.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).