From: Kevan Gelling <Kevan.Gelling@euphony.co.uk>
To: "'cygwin@cygwin.com'" <cygwin@cygwin.com>
Subject: 1.5.9: Trouble with setting variables using 'read' in a script
Date: Thu, 06 May 2004 13:25:00 -0000 [thread overview]
Message-ID: <201BC46BD93D244AB0A910D1203FFC1904B6A873@ecexchange02.euphony.com> (raw)
I'm having trouble setting variables using the 'read' command in bash.
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
I can get it work by explicitly declaring the file descriptor with the file
redirection, but I'd prefer to use a pipe.
- read -u 0 var <file ; echo $var
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?
My setup is Cygwin 1.5.9-1 and Bash 2.05b-16 under Windows XP Pro 5.1 SP1
Thanks,
Kevan
________________________________________________________________________
This e-mail has been scanned for all viruses by Star Internet. The
service is powered by MessageLabs. For more information on a proactive
anti-virus service working around the clock, around the globe, visit:
http://www.star.net.uk
________________________________________________________________________
--
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/
next reply other threads:[~2004-05-06 12:40 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-05-06 13:25 Kevan Gelling [this message]
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
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=201BC46BD93D244AB0A910D1203FFC1904B6A873@ecexchange02.euphony.com \
--to=kevan.gelling@euphony.co.uk \
--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).