delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/05/06/08:41:16

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sources.redhat.com/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sources.redhat.com/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
X-VirusChecked: Checked
X-Env-Sender: Kevan DOT Gelling AT euphony DOT co DOT uk
X-Msg-Ref: server-14.tower-22.messagelabs.com!1083847253!8451015
X-StarScan-Version: 5.2.10; banners=euphony.co.uk,-,-
X-Originating-IP: [62.173.120.154]
Message-ID: <201BC46BD93D244AB0A910D1203FFC1904B6A873@ecexchange02.euphony.com>
From: Kevan Gelling <Kevan DOT Gelling AT euphony DOT co DOT uk>
To: "'cygwin AT cygwin DOT com'" <cygwin AT cygwin DOT com>
Subject: 1.5.9: Trouble with setting variables using 'read' in a script
Date: Thu, 6 May 2004 13:40:51 +0100
MIME-Version: 1.0
Note-from-DJ: This may be spam

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/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019