Date: Fri, 27 Oct 95 03:06:55 PDT From: Ben Jackson <bjj@sequent.com> To: bugs@freebsd.org Subject: bug in /bin/sh for loops Message-ID: <199510271006.DAA29250@crg8.sequent.com>
next in thread | raw e-mail | index | archive | help
[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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199510271006.DAA29250>