From owner-freebsd-bugs Fri Oct 27 03:09:20 1995 Return-Path: owner-bugs Received: (from root@localhost) by freefall.freebsd.org (8.6.12/8.6.6) id DAA10804 for bugs-outgoing; Fri, 27 Oct 1995 03:09:20 -0700 Received: from gateway.sequent.com (gateway.sequent.com [138.95.18.1]) by freefall.freebsd.org (8.6.12/8.6.6) with ESMTP id DAA10799 for ; Fri, 27 Oct 1995 03:09:15 -0700 Received: from crg8.sequent.com (crg8.sequent.com [138.95.19.9]) by gateway.sequent.com (8.6.12/8.6.9) with ESMTP id DAA02704 for ; Fri, 27 Oct 1995 03:06:04 -0700 Received: from localhost (bjj@localhost) by crg8.sequent.com (8.6.12/8.6.9) with SMTP id DAA29250 for ; Fri, 27 Oct 1995 03:06:57 -0700 Message-Id: <199510271006.DAA29250@crg8.sequent.com> X-Authentication-Warning: crg8.sequent.com: Host localhost didn't use HELO protocol To: bugs@freebsd.org Subject: bug in /bin/sh for loops Date: Fri, 27 Oct 95 03:06:55 PDT From: Ben Jackson Sender: owner-bugs@freebsd.org Precedence: bulk [FreeBSD 2.1.0 951005-SNAP] The appended shell script doesn't have the expected output. The first half executes a loop which prints 0, 1, 2. The second half introduces a simple background job during each loop iteration. It seems that at the point where you run a background job in a { } list, the shell forks and the rest of the {} list runs in the new shell. This results in the value of VAR being lost (hence output 0,0,0) and having the main shell exit before the loop finishes running. All of the other shell-local information is also lost (jobs list, etc). Every other shell that claimed Bourne shell compatibility (zsh, ksh, AT&T sh) that I tried it on did what you'd expect. --Ben VAR=0 for X in 1 2 3 do echo $VAR VAR=$X done VAR=0 for X in 1 2 3 do echo $VAR VAR=$X /bin/ls > /dev/null & done