Date: Sun, 11 Aug 2002 19:36:56 +1000 From: "Chris Knight" <chris@aims.com.au> To: <freebsd-stable@freebsd.org> Subject: variable scope issue in -stable? Message-ID: <014d01c2411a$a2bee5d0$020aa8c0@aims.private>
next in thread | raw e-mail | index | archive | help
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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?014d01c2411a$a2bee5d0$020aa8c0>