Date: Sat, 22 Feb 1997 19:00:02 -0800 (PST) From: Mike Pritchard <mpp> To: freebsd-bugs Subject: Re: bin/2803: /bin/sh 'for' statement vs IFS setting problem Message-ID: <199702230300.TAA10336@freefall.freebsd.org>
next in thread | raw e-mail | index | archive | help
The following reply was made to PR bin/2803; it has been noted by GNATS. From: Mike Pritchard <mpp> 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"
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199702230300.TAA10336>