public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: "Jan Schormann" <Jan.Schormann@BrainLAB.com>
To: <cygwin@cygwin.com>
Subject: RE: 'read' and pipes, was: 1.5.9: Trouble with setting variables using 'read' in a script
Date: Thu, 06 May 2004 14:22:00 -0000	[thread overview]
Message-ID: <KCEOLMMHICICJKHPFOALEEFPCDAA.Jan.Schormann@BrainLAB.com> (raw)
In-Reply-To: <201BC46BD93D244AB0A910D1203FFC1904B6A873@ecexchange02.euphony.com>

> Another related quirk, is that variables set within
> 'while read' loops lose
> their values once the loop ends.  The following example
> displays "text text"
> within the loop and blank line outside.
>   - echo "text" |\
>     while read
>     do
>       foo=$REPLY ; bar="text"
>       echo $foo $bar
>     done
>     echo $foo $bar
>
> Is this a feature of bash or a bug?  If it is a feature is there a
> workaround?

As I learned shortly ago, the pipe '|' always forces
a new subshell. This holds for any shell, though someone
said that they differ in which side of the pipe gets
to be the subshell and which will be executed in the
main shell.

Thus, in your example, $foo and $bar only exist in the
subshell and will never be known to the surrounding
shell.

I think you can get closer to it using redirection



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

  parent reply	other threads:[~2004-05-06 14:20 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2004-05-06 13:25 Kevan Gelling
2004-05-06 14:20 ` Andy Rushton
2004-05-06 14:22 ` Jan Schormann [this message]
2004-05-06 15:27 ` cont'd - " Jan Schormann
2004-05-06 16:36 ` Brian Dessent

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=KCEOLMMHICICJKHPFOALEEFPCDAA.Jan.Schormann@BrainLAB.com \
    --to=jan.schormann@brainlab.com \
    --cc=cygwin@cygwin.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).