From scott@one.sabami.seaslug.org Sat Feb 22 15:46:30 1997 Received: from one.sabami.seaslug.org (sail.statsci.com [206.63.206.1]) by freefall.freebsd.org (8.8.5/8.8.5) with ESMTP id PAA00911 for ; Sat, 22 Feb 1997 15:46:19 -0800 (PST) Received: (from scott@localhost) by one.sabami.seaslug.org (8.7.5/8.7.3) id PAA14709; Sat, 22 Feb 1997 15:44:08 -0800 (PST) Message-Id: <199702222344.PAA14709@one.sabami.seaslug.org> Date: Sat, 22 Feb 1997 15:44:08 -0800 (PST) From: Scott Blachowicz Reply-To: Scott.Blachowicz@seaslug.org To: FreeBSD-gnats-submit@freebsd.org Subject: /bin/sh 'for' statement vs IFS setting problem X-Send-Pr-Version: 3.2 >Number: 2803 >Category: bin >Synopsis: /bin/sh 'for' doesn't token break properly >Confidential: no >Severity: non-critical >Priority: medium >Responsible: freebsd-bugs >State: closed >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Sat Feb 22 15:50:02 PST 1997 >Closed-Date: Sun Feb 23 21:46:58 PST 1997 >Last-Modified: Sun Feb 23 21:51:36 PST 1997 >Originator: Scott Blachowicz >Release: FreeBSD 2.1.5-RELEASE >Organization: none >Environment: FreeBSD one.sabami.seaslug.org 2.1.5-RELEASE FreeBSD 2.1.5-RELEASE #0: Thu Sep 26 21:57:44 PDT 1996 root@one.sabami.seaslug.org:/usr/src-CD/sys/compile/SABAMI i386 >Description: It APPEARS as if the IFS characters in the list of tokens to loop over get replaced by blanks after it has already been broken up into tokens instead of before the tokenizing. I ran across this using an autoconf generated configure script (trying to locate a program along a colon-separated list of directory names), so I imagine that others will stumble across this. >How-To-Repeat: I use this test script: #! /bin/sh IFS=' :' for tok in a:b:c do echo $tok done for tok in d e f do echo $tok done which SHOULD output 6 lines of output (letters a-f on separate lines), but what comes out is this: a b c d e f >Fix: 1) filter the list of tokens thru sed to replace the :'s with blanks: for tok in `echo a:b:c | sed 's/:/ /'` do echo $tok done 2) throw an extra "eval" in there: for tok in `eval echo a:b:c` do echo $tok done >Release-Note: >Audit-Trail: From: Mike Pritchard To: Scott.Blachowicz@seaslug.org Cc: FreeBSD-gnats-submit@freebsd.org Subject: Re: bin/2803: /bin/sh 'for' statement vs IFS setting problem Date: Sat, 22 Feb 1997 18:57:34 -0800 (PST) Scott Blachowicz wrote: > It APPEARS as if the IFS characters in the list of tokens to loop > over get replaced by blanks after it has already been broken up into > tokens instead of before the tokenizing. I ran across this using an > autoconf generated configure script (trying to locate a program > along a colon-separated list of directory names), so I imagine that > others will stumble across this. > > > >How-To-Repeat: > > I use this test script: > > #! /bin/sh > IFS=' :' > for tok in a:b:c > do > echo $tok > done > for tok in d e f > do > echo $tok > done > > which SHOULD output 6 lines of output (letters a-f on separate > lines), but what comes out is this: > > a b c > d > e > f > >Fix: > 1) filter the list of tokens thru sed to replace the :'s with > blanks: > > for tok in `echo a:b:c | sed 's/:/ /'` > do > echo $tok > done > > 2) throw an extra "eval" in there: > > for tok in `eval echo a:b:c` > do > echo $tok > done 3) IFS=' :' xxx=a:b:C for tok in $xxx do echo $tok done For the record, under 3.0, every shell I tried, ksh, sh and bash all work this way. Does this work the same way on other operating systems? E.g. Sunos/Solaris, or some other SYSv variety? -- Mike Pritchard mpp@FreeBSD.org "Go that way. Really fast. If something gets in your way, turn" From: Scott Blachowicz To: Mike Pritchard Cc: FreeBSD-gnats-submit@freebsd.org Subject: Re: bin/2803: /bin/sh 'for' statement vs IFS setting problem Date: Sat, 22 Feb 1997 21:31:34 -0800 Mike Pritchard wrote: > 3) > IFS=' :' > xxx=a:b:C > for tok in $xxx > do > echo $tok > done Ahhh...that looks a little less expensive than my workarounds... > For the record, under 3.0, every shell I tried, ksh, sh and bash > all work this way. Does this work the same way on other operating > systems? E.g. Sunos/Solaris, or some other SYSv variety? Well...here's a few... basil: IRIX basil 5.2 02282013 IP12 mips basil: a basil: b basil: c basil: d basil: e basil: f deck: OSF1 deck.statsci.com V3.2 17 alpha deck: a deck: b deck: c deck: d deck: e deck: f hoki: HP-UX hoki B.08.00 A 9000/42E 08000917b2cd hoki: a hoki: b hoki: c hoki: d hoki: e hoki: f mace: HP-UX mace A.09.05 A 9000/710 2012684354 two-user license mace: a mace: b mace: c mace: d mace: e mace: f main: SunOS main 5.3 Generic sun4m sparc main: a main: b main: c main: d main: e main: f spud: SunOS spud 4.1.1 7 sun4c spud: a spud: b spud: c spud: d spud: e spud: f Scott Blachowicz Ph: 206/283-8802x240 Mathsoft (Data Analysis Products Div) 1700 Westlake Ave N #500 scott@statsci.com Seattle, WA USA 98109 Scott.Blachowicz@seaslug.org From: j@uriah.heep.sax.de (J Wunsch) To: mpp@freefall.freebsd.org (Mike Pritchard) Cc: FreeBSD-gnats-submit@freefall.freebsd.org, Scott.Blachowicz@seaslug.org Subject: Re: bin/2803: /bin/sh 'for' statement vs IFS setting problem Date: Sun, 23 Feb 1997 09:33:20 +0100 As Mike Pritchard wrote: > > >How-To-Repeat: > > > > I use this test script: > > > > #! /bin/sh > > IFS=' :' > > for tok in a:b:c > > do > > echo $tok > > done > > for tok in d e f > > do > > echo $tok > > done > > > > which SHOULD output 6 lines of output (letters a-f on separate > > lines), but what comes out is this: > > > > a b c > > d > > e > > f > 3) > IFS=' :' > xxx=a:b:C > for tok in $xxx > do > echo $tok > done > > For the record, under 3.0, every shell I tried, ksh, sh and bash > all work this way. Does this work the same way on other operating > systems? E.g. Sunos/Solaris, or some other SYSv variety? $ echo ${.sh.version} Version M-12/28/93e $ for tok in a:b:c > do > echo $tok > done a b c $ That's ksh93, the genuine Korn shell. Since this is `by definition' also the Posix shell, i think we can close the case. -- cheers, J"org joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE Never trust an operating system you don't have sources for. ;-) State-Changed-From-To: open->closed State-Changed-By: mpp State-Changed-When: Sun Feb 23 21:46:58 PST 1997 State-Changed-Why: We are bug-bug compatible with the "POSIX" ksh shell, in regards to this problem, so this should be closed according to joerg. >Unformatted: