public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
From: Brian Dessent <brian@dessent.net>
To: "'cygwin@cygwin.com'" <cygwin@cygwin.com>
Subject: Re: 1.5.9: Trouble with setting variables using 'read' in a script
Date: Thu, 06 May 2004 16:36:00 -0000	[thread overview]
Message-ID: <409A6618.79304D0D@dessent.net> (raw)
In-Reply-To: <201BC46BD93D244AB0A910D1203FFC1904B6A873@ecexchange02.euphony.com>

Kevan Gelling wrote:

> All of the following lines fail to set $var and return a blank line.
>   - echo "text" | read var ; echo $var
>   - cat file | read var ; echo $var
>   - read var < file | echo $var

The other reply by Andy R is spot on, you can't modify the current
environment from a subshell.  If you want to use the above idioms, you
can use:

echo "text" | (read var; echo $var)

This causes the 'echo' to be run from the same subshell as 'read', so it
will see the modified environment.  None of this is specific to Cygwin,
it's the design of sh/ash/bash type shells, and so there are better
places to ask about these kinds of things than the Cygwin list.  Try
looking for newsgroups, FAQs, or books dealing with Bourne shell
programming.

Brian

--
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 16:21 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 ` 'read' and pipes, was: " Jan Schormann
2004-05-06 15:27 ` cont'd - " Jan Schormann
2004-05-06 16:36 ` Brian Dessent [this message]

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=409A6618.79304D0D@dessent.net \
    --to=brian@dessent.net \
    --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).