From owner-freebsd-stable Sun Aug 11 2:51:57 2002 Delivered-To: freebsd-stable@freebsd.org Received: from mx1.FreeBSD.org (mx1.FreeBSD.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 88D8437B400 for ; Sun, 11 Aug 2002 02:51:53 -0700 (PDT) Received: from postoffice.aims.com.au (eth0.lnk.aims.com.au [203.31.73.253]) by mx1.FreeBSD.org (Postfix) with ESMTP id DA28943E3B for ; Sun, 11 Aug 2002 02:51:51 -0700 (PDT) (envelope-from chris@aims.com.au) Received: from postoffice.aims.com.au (nts-ts1.aims.private [192.168.10.2]) by postoffice.aims.com.au with ESMTP id g7B9poe06855 for ; Sun, 11 Aug 2002 19:51:50 +1000 (EST) (envelope-from chris@aims.com.au) Received: from ntsts1 by aims.com.au with SMTP (MDaemon.v3.5.3.R) for ; Sun, 11 Aug 2002 19:36:57 +1000 Reply-To: From: "Chris Knight" To: Subject: variable scope issue in -stable? Date: Sun, 11 Aug 2002 19:36:56 +1000 Message-ID: <014d01c2411a$a2bee5d0$020aa8c0@aims.private> MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 (Normal) X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook CWS, Build 9.0.2416 (9.0.2911.0) X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4807.1700 Importance: Normal X-Return-Path: chris@aims.com.au X-MDaemon-Deliver-To: freebsd-stable@freebsd.org Sender: owner-freebsd-stable@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG Howdy, I've got the following problem in FreeBSD-stable, and also 4.6, 4.5 and 4.2. The following code is not behaving as expected: ----- #!/bin/sh match=0 anycmd | while read line do case "$line" in "command") match=1 echo "match=$match" ;; *) ;; esac done echo "match=$match" ----- The output of the above results in: match=1 match=0 I'd expect match to be a global definition, but match loses its value outside of the while block. It appears that read stuffs things up - if I change the while expression to something other than read, then the variable scope behaves correctly. Or am I missing something? Regards, Chris Knight Systems Administrator AIMS Independent Computer Professionals Tel: +61 3 6334 6664 Fax: +61 3 6331 7032 Mob: +61 419 528 795 Web: http://www.aims.com.au To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-stable" in the body of the message